posix

system call to map memory to a file descriptor (inverse mmap)?

I want to be able to map memory to a file descriptor so I can use some existing functions that need a file descriptor. Here's essentially what I'm looking for: void do_operation1(int fd); char data[DATA_MAX] = { /* embedded binary data */ }; int fd = addr_to_fd(data, DATA_MAX); do_operation1(fd); /* ... operate on fd ... */ What sy...

Simple POSIX threads question

Hi, I have this POSIX thread: void subthread(void) { while(!quit_thread) { // do something ... // don't waste cpu cycles if(!quit_thread) usleep(500); } // free resources ... // tell main thread we're done quit_thread = FALSE; } Now I want to terminate subthread() from my main thread. I've tried th...

How to convert a PCRE to a POSIX RE?

This interesting question http://stackoverflow.com/questions/2837267/ concerned how to do a negative look-ahead in MySQL. The poster wanted to get the effect of Kansas(?! State) because MySQL doesn't implement look-ahead assertions, a number of answers came up the equivalent Kansas($|[^ ]| ($|[^S])| S($|[^t])| St($|[^a])| Sta($|[^t])...

Equivalent of open_memstream for MSVC

Hi, I am using *open_memstream* in a library of mine, but I would like to port this library to MSVC. It seems there are no equivalent function available, but is there something similar enough? What *open_memstream* does is it takes a char** destination and size and returns a FILE* which you many write to, the data is stored in a dynamic...

Different standard streams per POSIX thread

Is there any possibility to achieve different redirections for standard output like printf(3) for different POSIX thread? What about standard input? I have lot of code based on standard input/output and I only can separate this code into different POSIX thread, not process. Linux operation system, C standard library. I know I can refact...

POSIX: allocate 64KB on 64KB boundary.

I would really like to actually only allocate 64KB of memory, not 128KB and then do the alignment manually - far too wasteful. VirtualAlloc on windows gives precisely this behavior. Supposedly there's code in SquirrelFish for doing this on just about every platform, but I haven't managed to locate it. Is there a space efficient way to al...

what if _POSIX_VDISABLE value is -1?

In POSIX _POSIX_VDISABLE value if -1, there is no disabling character for special character for all the terminal device files; otherwise the value is the disabling character value.. Can please anyone help me understand this. I m not able to get the exact meaning of this. Please ...

Serial: write() throttling?

Hi everyone, I'm working on a project sending serial data to control animation of LED lights, which need to stay in sync with an animation engine. There seems to be a large serial write buffer (OSX (POSIX) + FTDI chipset usb serial device), so without manually throttling calls to write(), the software can get several seconds ahead of th...

Getting the file name of files dropped on the script

...

How good is the memory mapped Circular Buffer on Wikipedia?

I'm trying to implement a circular buffer in C, and have come across this example on Wikipedia. It looks as if it would provide a really nice interface for anyone reading from the buffer, as reads which wrap around from the end to the beginning of the buffer are handled automatically. So all reads are contiguous. However, I'm a bit unsu...

Problem with the POSIX module

After moving my mod_perl site from Linux hosting to FreeBSD, I have this error in the logfile: Your vendor has not defined POSIX macro SIGRTMIN, used at ../../lib/POSIX.pm (autosplit into ../../lib/auto/POSIX/SigRt/_init.al) line 993\n The script just imports POSIX and utilizes some functions (ceil, etc) How can I solve th...

What does ECONNRESET mean in the context of an AF_LOCAL socket?

I understand that for TCP sockets ECONNRESET has got something to do with RST packets. But I've seen ECONNRESET errors for AF_LOCAL sockets too, on read() and write() calls. What does this mean? How is ECONNRESET different from read() returning 0 or write() throwing EPIPE? ...

how to clear stack after stack overflow signal occur

In pthread, After reaching yellow zone in stack, signal handler stop the recursive function by making it return however, we can only continue to use extra area in yellow zone, how to clear the rubbish before the yellow zone in the thread stack ? (Copied from "answers"): #include <pthread.h> #include <stdio.h> #include <stdlib.h> ...

simulating atm communication without atm switch.

Hi everyone there, can anybody tell me how to make file descriptors behave like atm nodes in /dev directory. Since i dnt have atm switch to test my program, i have to test with normal files, is there any method to make special type of file descriptors that behave like atm nodes. ...

Using sqlite from vala without dependence on glib

I need to use the Sqlite vapi without any depedence on GLib. SQlite is non-gobject library, so it should be possible to do that. However, when I try to compile the following file with the --profile posix option, using Sqlite; void main() { stdout.printf("Hello, World!"); } I get am error messages: sqlite3.vapi:357.56-357.59: e...

How to get POSIX strerror_r instead of GNU version?

How do I get the POSIX strerror_r instead of GNU version? I'm compiling with g++ on Ubuntu 8.04 with glibc version 2.7 ( based on what's in ). Edit On the above man page it says: Feature Test Macro Requirements for glibc (see feature_test_macros(7)): The XSI-compliant version of strerror_r() is provided if: (_POSIX_C_SOURC...

Locking mechanisms for shared-memory consistency

Hi all, I'm developing a mechanism for interchanging data between two or more processes using shared memory on linux. The problem is some level of concurrency control is required to maintain data integrity on the shared memory itself, and as I'm specting that sometime or another my process could be killed/crash, common lock mechanisms d...

boost::this_thread::sleep() vs. nanosleep()?

I recently came across the need to sleep the current thread for an exact period of time. I know of two methods of doing so on a POSIX platform: using nanosleep() or using Boost::this_thread::sleep(). Out of curiosity more than anything else, I was wondering what the differences are between the two approaches. Is there any difference i...

virtual memory consumption of pthreads

Hello I developed a multi-threaded TCP server application that allows 10 concurrent connections receives continuous requests from them, after some processing requests, responds them to clients. I'm running it on a TI OMAP l137 processor based board it runs Monta Vista Linux. Threads are created per client ie 10 threads and it's pre-thre...

Check to see if a message is in a POSIX message queue w/o removing it from the queue?

POSIX provides a way to read a message queue using its mq_receive function. This function also removes it from the queue. I need to find a way to check to see if a message is in the queue without removing it. ...