|
|
1.1 ! root 1: .\" Copyright (c) 1983 Regents of the University of California. ! 2: .\" All rights reserved. The Berkeley software License Agreement ! 3: .\" specifies the terms and conditions for redistribution. ! 4: .\" ! 5: .\" @(#)fcntl.2 6.4 (Berkeley) 5/22/86 ! 6: .\" ! 7: .TH FCNTL 2 "May 22, 1986" ! 8: .UC 5 ! 9: .SH NAME ! 10: fcntl \- file control ! 11: .SH SYNOPSIS ! 12: .nf ! 13: .ft B ! 14: #include <fcntl.h> ! 15: .PP ! 16: .ft B ! 17: res = fcntl(fd, cmd, arg) ! 18: int res; ! 19: int fd, cmd, arg; ! 20: .ft R ! 21: .SH DESCRIPTION ! 22: .I Fcntl ! 23: provides for control over descriptors. ! 24: The argument ! 25: .I fd ! 26: is a descriptor to be operated on by ! 27: .I cmd ! 28: as follows: ! 29: .TP 15 ! 30: F_DUPFD ! 31: Return a new descriptor as follows: ! 32: .IP ! 33: Lowest numbered available descriptor greater than or equal to ! 34: .I arg. ! 35: .IP ! 36: Same object references as the original descriptor. ! 37: .IP ! 38: New descriptor shares the same file pointer if the object ! 39: was a file. ! 40: .IP ! 41: Same access mode (read, write or read/write). ! 42: .IP ! 43: Same file status flags (i.e., both file descriptors ! 44: share the same file status flags). ! 45: .IP ! 46: The close-on-exec flag associated with the new file descriptor ! 47: is set to remain open across ! 48: .IR execv (2) ! 49: system calls. ! 50: .TP 15 ! 51: F_GETFD ! 52: Get the close-on-exec flag associated with the file descriptor ! 53: .IR fd . ! 54: If the low-order bit is 0, the file will remain open across ! 55: .IR exec , ! 56: otherwise the file will be closed upon execution of ! 57: .I exec. ! 58: .TP 15 ! 59: F_SETFD ! 60: Set the close-on-exec flag associated with ! 61: .I fd ! 62: to the low order bit of ! 63: .I arg ! 64: (0 or 1 as above). ! 65: .TP 15 ! 66: F_GETFL ! 67: Get descriptor status flags, as described below. ! 68: .TP 15 ! 69: F_SETFL ! 70: Set descriptor status flags. ! 71: .TP 15 ! 72: F_GETOWN ! 73: Get the process ID or process group ! 74: currently receiving SIGIO and SIGURG ! 75: signals; process groups are returned ! 76: as negative values. ! 77: .TP ! 78: F_SETOWN ! 79: Set the process or process group ! 80: to receive SIGIO and SIGURG signals; ! 81: process groups are specified by supplying ! 82: .I arg ! 83: as negative, otherwise ! 84: .I arg ! 85: is interpreted as a process ID. ! 86: .LP ! 87: The flags for the F_GETFL and F_SETFL flags are as follows: ! 88: .TP 15 ! 89: FNDELAY ! 90: Non-blocking I/O; if no data is available to a ! 91: .I read ! 92: call, or if a write operation would block, ! 93: the call returns -1 with the error EWOULDBLOCK. ! 94: .TP ! 95: FAPPEND ! 96: Force each write to append at the end of file; ! 97: corresponds to the O_APPEND flag of ! 98: .IR open (2). ! 99: .TP ! 100: FASYNC ! 101: Enable the SIGIO signal to be sent to the process group ! 102: when I/O is possible, e.g., ! 103: upon availability of data to be read. ! 104: .SH "RETURN VALUE ! 105: Upon successful completion, the value returned depends on ! 106: .I cmd ! 107: as follows: ! 108: .sp .5v ! 109: .nf ! 110: .ta .25i 1.25i ! 111: F_DUPFD A new file descriptor. ! 112: F_GETFD Value of flag (only the low-order bit is defined). ! 113: F_GETFL Value of flags. ! 114: F_GETOWN Value of file descriptor owner. ! 115: other Value other than \-1. ! 116: .fi ! 117: .sp .5v ! 118: Otherwise, a value of \-1 is returned and ! 119: .I errno ! 120: is set to indicate the error. ! 121: .SH ERRORS ! 122: .I Fcntl ! 123: will fail if one or more of the following are true: ! 124: .TP 15 ! 125: [EBADF] ! 126: .I Fildes ! 127: is not a valid open file descriptor. ! 128: .TP 15 ! 129: [EMFILE] ! 130: .I Cmd ! 131: is F_DUPFD and the maximum allowed number of file descriptors are currently ! 132: open. ! 133: .TP 15 ! 134: [EINVAL] ! 135: .I Cmd ! 136: is F_DUPFD and ! 137: .I arg ! 138: is negative or greater than the maximum allowable number ! 139: (see ! 140: .IR getdtablesize (2)). ! 141: .TP 15 ! 142: [ESRCH] ! 143: .I Cmd ! 144: is F_SETOWN and ! 145: the process ID given as argument is not in use. ! 146: .SH "SEE ALSO ! 147: close(2), execve(2), getdtablesize(2), open(2), sigvec(2) ! 148: .SH BUGS ! 149: The asynchronous I/O facilities of FNDELAY and FASYNC ! 150: are currently available only for tty and socket operations.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.