posix

Function overloading in C

Today, looking at the man page for open(), I've noticed this function is 'overloaded': int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); I didn't thought it's possible on C. What's the 'trick' for achieving this ? LATER EDIT: So it's not really overloading, because when using va...

Quote POSIX shell special characters in Python output

There are times that I automagically create small shell scripts from Python, and I want to make sure that the filename arguments do not contain non-escaped special characters. I've rolled my own solution, that I will provide as an answer, but I am almost certain I've seen such a function lost somewhere in the standard library. By “lost” ...

How do I retrieve the number of processors on C / Linux ?

I am writing a small C application that use some threads for processing data. I want to be able to know the number of processors on a certain machine, without using system() & in combination to a small script. The only way i can think of is to parse /proc/cpuinfo. Any other useful suggestions ? ...

What the best approach to iterate and "store" files over a directory in C (Linux) ?

I have written a function that checks if to files are duplicates or not. This function signature is: int check_dup_memmap(char *f1_name, char *f2_name) It returns: (-1) - If something went wrong; (0) - If the two files are similar; (+1) - If the two files are different; The next step is to write a function that iterates through a...

Using pthread condition variable with rwlock

Hello, I'm looking for a way to use pthread rwlock structure with conditions routines in C++. I have two questions: First: How is it possible and if we can't, why ? Second: Why current POSIX pthread have not implemented this behaviour ? To understand my purpose, I explain what will be my use: I've a producer-consumer model dealing ...

POSIX regexp for finding everything between wordX and wordY

I have string as: FOO /some/%string-in.here BAR I would like to get everything between FOO and BAR but NOT including FOO[:space:] and NOT including [:space:]BAR Any ideas it will be appreciate it. ...

looking for information on porting Linux apps to windows

Today I've encountered a very good book : UNIX to Linux® Porting: A Comprehensive Reference By Alfredo Mendoza, Chakarat Skawratananond, Artis Walker This reminded me of the thing I always wanted to know. "Porting Linux apps to Windows". I mean porting native Linux apps to native Windows with no platforms involved. If I can find an...

Reference a GNU C (POSIX) DLL built in GCC against Cygwin, from C#/NET

Here is what I want: I have a huge legacy C/C++ codebase written for POSIX, including some very POSIX specific stuff like pthreads. This can be compiled on Cygwin/GCC and run as an executable under Windows with the Cygwin DLL. What I would like to do is build the codebase itself into a Windows DLL that I can then reference from C# and w...

Can a PIPE in LINUX ever lose data?

And is there a upper limit on how much data can it contain? ...

Is there a POSIX syscall to resolve file system paths?

Is there a POSIX syscall to resolve filesystem paths? I have the CWD for a path, as well as the path to a file from that CWD. I can't use chdir to switch to the directory because I need to resolve paths from multiple threads simultaneously. I considered appending a / in between the CWD and the path, but for some reason it feels like that...

getaddrinfo is not statically compiled

I have included the header netdb.h, where getaddrinfo is included, but gcc issues this warning: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking gcc -m32 -static -s -O2 -std=c99 -D_POSIX_C_SOURCE=200112L myprogram.c How can I statically comp...

program to print odd numbers and even numbers on seperate threads

Hi, I am learning programming using pthreads. How can I write a program to print odd numbers and even numbers on separate threads. ...

alignment and granularity of mmap

I am confused by the specification of mmap. Let pa be the return address of mmap (the same as the specification) pa = mmap(addr, len, prot, flags, fildes, off); In my opinion after the function call succeed the following range is valid [ pa, pa+len ) My question is whether the range of the following is still valid? [ rou...

Is there a way to ‘join’ (block) in POSIX threads, without exiting the joinee?

I’m buried in multithreading / parallelism documents, trying to figure out how to implement a threading implementation in a programming language I’ve been designing. I’m trying to map a mental model to the pthreads.h library, but I’m having trouble with one thing: I need my interpreter instances to continue to exist after they complete ...

How to check if a file descriptor has any data available?

I'd like to know if a fd has data available for reading. I have tried ioctl with FIONREAD but that results in a "Operation not supported error". Any ideas? ...

getnameinfo specifies socklen_t

The 2nd arg for the getnameinfo prototype asks for a socklen_t type but sizeof uses size_t. So how can I get socklen_t ? Prototype: int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags); Example: struct socka...

Is there a posix-way to ensure two files are flushed in sequence without blocking?

In my program, I hold two files open for writing, a content-file, containing chunks of data, and an index-file, containing a map over which chunks of data has been written so far. I would like to flush them both to disc, as performant as possible, with the only constraint that the blocks in the data-file must be written before the corre...

Condition Variable in Shared Memory - is this code POSIX-conformant?

Does the POSIX standard allow a named shared memory block to contain a mutex and condition variable? We've been trying to use a mutex and condition variable to synchronise access to named shared memory by two processes on a LynuxWorks LynxOS-SE system (POSIX-conformant). One shared memory block is called "/sync" and contains the mutex ...

Linux and I/O completion ports?

Using winsock, you can configure sockets or seperate I/O operations to "overlap". This means that calls to perform I/O are returned immediately, while the actual operations are completed asynchronously by separate worker threads. Winsock also provides "completion ports". From what I understand, a completion port acts as a multiplexer of...

Lock a mutex multiple times in the same thread

Hi, I'm developing an application on an embedded linux OS (uClinux) and I need to be able to lock the mutex more than once (by the same thread). I have a mutex and a mutexattr defined and initialized as follows: pthread_mutexattr_t waiting_barcode_mutexattr; pthread_mutex_t waiting_barcode_mutex; pthread_mutexattr_init(&waiting_barco...