NAME | SYNOPSIS | FEATURES | DESCRIPTION | RETURN VALUES | ERRORS | ATTRIBUTES | SEE ALSO
#include <fcntl.h>int fcntl(int fildes, int cmd, ... /*arg */);
MSDOSFS, NFS_CLIENT, UFS, POSIX_SOCKETS, POSIX_SHM
The fcntl system call provides a control mechanism for open files. The fildes filed contains a file descriptor obtained from an open(2POSIX), dup(2POSIX), accept(2POSIX), socket(2POSIX) or shm_open(2POSIX) system call.
The commands available are:
Lowest numbered available descriptor greater than or equal to arg
Same object references as the original descriptor
New descriptor shares the same file offset if the object was a file
Same access mode (read, write or read/write)
Same file status flags (i.e., both file descriptors share the same file status flags)
The close-on-exec flag associated with the new file descriptor is set to remain open across afexec(2POSIX) system calls.
Get the close-on-afexec flag associated with the file descriptor fildes. If the low-order bit is 0 the file will remain open across a local afexec(2POSIX), otherwise the file will be closed upon execution of afexec(2POSIX).
Set the close-on-afexec flag associated with fildes to the low-order bit of arg (0 or 1 as above).
Get fildes status flags. This flag is not supported by shared memory objects.
Set fildes status flags to the integer value given as the third argument. Only the O_APPEND and O_NONBLOCK flags can be set. This flag is not supported by shared memory objects.
Upon successful completion, the value returned depends on cmd as follows:
A new file descriptor
Value of the flag (only the low-order bit is defined)
Value other than -1
Value of file status flags. The return value will not be negative.
Value other than -1
Otherwise, a value of -1 is returned and errno is set to indicate one of the following error conditions.
fildes is not a valid open file descriptor.
cmd is not a valid command.
fildes defines a shared memory object or a message queue object, and either the F_GETLK or F_SETLK or F_SETLKW command was specified.
The F_GETOWN or F_SETOWN command was specified.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
accept(2POSIX), afexec(2K), close(2POSIX), dup(2POSIX), open(2POSIX), socket(2POSIX), shm_open(2POSIX)
NAME | SYNOPSIS | FEATURES | DESCRIPTION | RETURN VALUES | ERRORS | ATTRIBUTES | SEE ALSO