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...
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” ...
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 ?
...
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...
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 ...
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.
...
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...
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...
And is there a upper limit on how much data can it contain?
...
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...
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...
Hi,
I am learning programming using pthreads.
How can I write a program to print odd numbers and even numbers on separate threads.
...
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...
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 ...
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?
...
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...
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...
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 ...
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...
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...