Which systems define EAGAIN and EWOULDBLOCK as different values?

There were some… http://www.gnu.org/s/hello/manual/libc/Error-Codes.html Portability Note: In many older Unix systems, this condition was indicated by EWOULDBLOCK, which was a distinct error code different from EAGAIN. To make your program portable, you should check for both codes and treat them the same. http://lists.parisc-linux.org/hypermail/parisc-linux/9895.html On some SysV systems EAGAIN != EWOULDBLOCK. I think we inherited the … Read more

Setting creation or change timestamps

For ext2/3 and possibly for ext4 you can do this with debugfs tool, assuming you want to change the ctime of file /tmp/foo which resides in disk /dev/sda1 we want to set ctime to 201001010101 which means 01 January 2010, time 01:01: Warning: Disk must be unmounted before this operation # Update ctime debugfs -w … Read more

Who uses POSIX realtime signals and why?

First of all, note that Ben’s answer is correct. As far as I can tell, the whole purpose of realtime signals in POSIX is as a realtime delivery mechanism for AIO, message queue notifications, timer expirations, and application-defined signals (both internal and inter-process). With that said, signals in general are a really bad way to … Read more

Why did POSIX mandate CHAR_BIT==8?

Because the vast majority of standards (related to communication) out of ANSI and ISO talk in terms of octets (8-bit values). There is none of that wishy-washy variable-sized character nonsense 🙂 And, since a rather large quantity of C code used char or unsigned char for storing and/or manipulating these values, and assumed they were … Read more

UNIX Portable Atomic Operations

As of C11 there is an optional Atomic library which provides atomic operations. This is portable to whatever platform that has a C11 compiler (like gcc-4.9) with this optional feature. The presence of the atomic can be checked with __STDC_NO_ATOMICS__and the presence of <stdatomic.h> atomic.c #include <stdio.h> #include <stdlib.h> #ifndef __STDC_NO_ATOMICS__ #include <stdatomic.h> #endif int … Read more

getline() vs. fgets(): Control memory allocation

My question is: Isn’t that dangerous? What if by accident or malicious intent someone creates a 100GB file with no ‘\n’ byte in it – won’t that make my getline() call allocate an insane amount of memory? Yes, what you describe is a plausible risk. However, if the program requires loading an entire line into … Read more

Connecting n commands with pipes in a shell?

Nothing complex here, just have in mind that the last command should output to the original process’ file descriptor 1 and the first should read from original process file descriptor 0. You just spawn the processes in order, carrying along the input side of the previous pipe call. So, here’s are the types: #include <unistd.h> … Read more

tech