I am trying to code a nonblocking pipe, my code is as follow
int fd = open(fifo_path, O_RDONLY | O_NONBLOCK );
int flag = fcntl(fd, F_GETFL, 0);
printf("flag is %d \n", flag);
The flag printout is 34816 in decimal (or 8800 in hex). I have checked the fcntl-Linux.h, I have found the value should be 04000 in hex (O_RDONLY | O_NONBLOCK. is 0 | 04000)
Is my calculation rite? Just trying to check the numbers
Thanks Regards
Using the information from the POSIX specifications of
fcntl()and<fcntl.h>, you might come up with this code. It uses some error reporting code that is available in my SOQ (Stack Overflow Questions) repository on GitHub as filesstderr.candstderr.hin the src/libsoq sub-directory.When run on a MacBook Pro running macOS Ventura 13.2.1, I get the output:
Clearly, the code could/should be revised to take a file type and file name as an argument, a value for the open mode, and a value for the file permissions. It might be commanded to create the file (like it creates the temporary FIFO), but would not create the file by default, and so on — the design requires a bit of thought, especially if the open modes and permissions are to be strings rather than just numbers.