Open for private access a file associated with a given descriptor
#include <unistd.h> int openfd( int fd, int oflag );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The openfd() function opens the file associated with the file descriptor, fd. This is similar to dup(), except the new fd has private access modes and offset. The access mode, oflag, must be equal to or more restrictive than the access mode of the source fd.
A file descriptor, or -1 if an error occurred (errno is set).
#include <unistd.h> #include <stdlib.h> #include <fcntl.h> int main ( void ) { int fd, fd2, oflag; fd = open ("/etc/passwd", O_RDONLY); fd2 = openfd ( fd, O_RDONLY ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |