p l -bullet -compact -offset 4n t Lowest numbered available descriptor greater than or equal to .Fa arg . t Same object references as the original descriptor. t New descriptor shares the same file offset if the object was a file. t Same access mode (read, write or read/write). t Same file status flags (i.e., both file descriptors share the same file status flags). t The close-on-exec flag associated with the new file descriptor is set to remain open across .Xr execv 2 system calls. .El t Dv F_GETFD Get the close-on-exec flag associated with the file descriptor .Fa fd . If the low-order bit of the returned value is 0, the file will remain open across .Fn exec , otherwise the file will be closed upon execution of .Fn exec .Fa ( arg is ignored). t Dv F_SETFD Set the close-on-exec flag associated with .Fa fd to the low order bit of .Fa arg (0 or 1 as above). t Dv F_GETFL Get descriptor status flags, as described below .Fa ( arg is ignored). t Dv F_SETFL Set descriptor status flags to .Fa arg . t Dv F_GETOWN Get the process ID or process group currently receiving .Dv SIGIO and .Dv SIGURG signals; process groups are returned as negative values .Fa ( arg is ignored). t Dv F_SETOWN Set the process or process group to receive .Dv SIGIO and .Dv SIGURG signals; process groups are specified by supplying .Fa arg as negative, otherwise .Fa arg is interpreted as a process ID. .El
p The flags for the .Dv F_GETFL and .Dv F_SETFL flags are as follows: l -tag -width F_GETOWNX t Dv O_NDELAY Non-blocking I/O; if no data is available to a .Xr read call, or if a .Xr write operation would block, the read or write call returns -1 with the error .Er EWOULDBLOCK . t Dv O_APPEND Force each write to append at the end of file; corresponds to the .Dv O_APPEND flag of .Xr open 2 . t Dv O_ASYNC Enable the .Dv SIGIO signal to be sent to the process group when I/O is possible, e.g., upon availability of data to be read. .El .Sh RETURN VALUES Upon successful completion, the value returned depends on .Fa cmd as follows: l -tag -width F_GETOWNX -offset indent t Dv F_DUPFD A new file descriptor. t Dv F_GETFD Value of flag (only the low-order bit is defined). t Dv F_GETFL Value of flags. t Dv F_GETOWN Value of file descriptor owner. t other Value other than -1. .El
p Otherwise, a value of -1 is returned and .Va errno is set to indicate the error. .Sh ERRORS .Fn Fcntl will fail if: l -tag -width Er t Bq Er EBADF .Fa Fildes is not a valid open file descriptor. t Bq Er EMFILE .Fa Cmd is .Dv F_DUPFD and the maximum allowed number of file descriptors are currently open. t Bq Er EINVAL .Fa Cmd is .Dv F_DUPFD and .Fa arg is negative or greater than the maximum allowable number (see .Xr getdtablesize 2 ) . t Bq Er ESRCH .Fa Cmd is .Dv F_SETOWN and the process ID given as argument is not in use. .El .Sh SEE ALSO .Xr close 2 , .Xr execve 2 , .Xr getdtablesize 2 , .Xr open 2 , .Xr sigvec 2 .Sh BUGS The asynchronous I/O facilities of .Dv FNDELAY and .Dv FASYNC are currently available only for tty and socket operations. .Sh HISTORY The .Fn fcntl function call appeared in x 4.2 .