Commit | Line | Data |
---|---|---|
88b3ccf2 KB |
1 | .\" Copyright (c) 1983 The Regents of the University of California. |
2 | .\" All rights reserved. | |
c24fefdc | 3 | .\" |
91cff1e1 | 4 | .\" %sccs.include.redist.man% |
88b3ccf2 | 5 | .\" |
3a2b8980 | 6 | .\" @(#)fcntl.2 6.10 (Berkeley) %G% |
c24fefdc | 7 | .\" |
931b8415 CL |
8 | .Dd |
9 | .Dt FCNTL 2 | |
10 | .Os BSD 4.2 | |
11 | .Sh NAME | |
12 | .Nm fcntl | |
13 | .Nd file control | |
14 | .Sh SYNOPSIS | |
ac6404fc | 15 | .Fd #include <fcntl.h> |
931b8415 CL |
16 | .Ft int |
17 | .Fn fcntl "int fd" "int cmd" "int arg" | |
18 | .Sh DESCRIPTION | |
19 | .Fn Fcntl | |
c24fefdc KM |
20 | provides for control over descriptors. |
21 | The argument | |
931b8415 | 22 | .Fa fd |
c24fefdc | 23 | is a descriptor to be operated on by |
931b8415 | 24 | .Fa cmd |
c24fefdc | 25 | as follows: |
931b8415 CL |
26 | .Bl -tag -width F_GETOWNX |
27 | .It Dv F_DUPFD | |
c24fefdc | 28 | Return a new descriptor as follows: |
931b8415 CL |
29 | .Pp |
30 | .Bl -bullet -compact -offset 4n | |
31 | .It | |
c24fefdc | 32 | Lowest numbered available descriptor greater than or equal to |
931b8415 CL |
33 | .Fa arg . |
34 | .It | |
c24fefdc | 35 | Same object references as the original descriptor. |
931b8415 CL |
36 | .It |
37 | New descriptor shares the same file offset if the object | |
c24fefdc | 38 | was a file. |
931b8415 | 39 | .It |
c24fefdc | 40 | Same access mode (read, write or read/write). |
931b8415 | 41 | .It |
c24fefdc KM |
42 | Same file status flags (i.e., both file descriptors |
43 | share the same file status flags). | |
931b8415 | 44 | .It |
c24fefdc KM |
45 | The close-on-exec flag associated with the new file descriptor |
46 | is set to remain open across | |
931b8415 | 47 | .Xr execv 2 |
c24fefdc | 48 | system calls. |
931b8415 CL |
49 | .El |
50 | .It Dv F_GETFD | |
c24fefdc | 51 | Get the close-on-exec flag associated with the file descriptor |
931b8415 CL |
52 | .Fa fd . |
53 | If the low-order bit of the returned value is 0, | |
54 | the file will remain open across | |
55 | .Fn exec , | |
c24fefdc | 56 | otherwise the file will be closed upon execution of |
931b8415 CL |
57 | .Fn exec |
58 | .Fa ( arg | |
59 | is ignored). | |
60 | .It Dv F_SETFD | |
c24fefdc | 61 | Set the close-on-exec flag associated with |
931b8415 | 62 | .Fa fd |
c24fefdc | 63 | to the low order bit of |
931b8415 | 64 | .Fa arg |
c24fefdc | 65 | (0 or 1 as above). |
931b8415 CL |
66 | .It Dv F_GETFL |
67 | Get descriptor status flags, as described below | |
68 | .Fa ( arg | |
69 | is ignored). | |
70 | .It Dv F_SETFL | |
71 | Set descriptor status flags to | |
72 | .Fa arg . | |
73 | .It Dv F_GETOWN | |
c24fefdc | 74 | Get the process ID or process group |
931b8415 CL |
75 | currently receiving |
76 | .Dv SIGIO | |
77 | and | |
78 | .Dv SIGURG | |
c24fefdc | 79 | signals; process groups are returned |
931b8415 CL |
80 | as negative values |
81 | .Fa ( arg | |
82 | is ignored). | |
83 | .It Dv F_SETOWN | |
c24fefdc | 84 | Set the process or process group |
931b8415 CL |
85 | to receive |
86 | .Dv SIGIO | |
87 | and | |
88 | .Dv SIGURG | |
89 | signals; | |
c24fefdc | 90 | process groups are specified by supplying |
931b8415 | 91 | .Fa arg |
c24fefdc | 92 | as negative, otherwise |
931b8415 | 93 | .Fa arg |
c24fefdc | 94 | is interpreted as a process ID. |
931b8415 CL |
95 | .El |
96 | .Pp | |
97 | The flags for the | |
98 | .Dv F_GETFL | |
99 | and | |
100 | .Dv F_SETFL | |
101 | flags are as follows: | |
102 | .Bl -tag -width F_GETOWNX | |
d9927876 | 103 | .It Dv O_NONBLOCK |
c24fefdc | 104 | Non-blocking I/O; if no data is available to a |
931b8415 CL |
105 | .Xr read |
106 | call, or if a | |
107 | .Xr write | |
108 | operation would block, | |
109 | the read or write call returns -1 with the error | |
3a2b8980 | 110 | .Er EAGAIN . |
931b8415 | 111 | .It Dv O_APPEND |
c24fefdc | 112 | Force each write to append at the end of file; |
931b8415 CL |
113 | corresponds to the |
114 | .Dv O_APPEND | |
115 | flag of | |
116 | .Xr open 2 . | |
117 | .It Dv O_ASYNC | |
118 | Enable the | |
119 | .Dv SIGIO | |
120 | signal to be sent to the process group | |
d4bad45b | 121 | when I/O is possible, e.g., |
c24fefdc | 122 | upon availability of data to be read. |
931b8415 CL |
123 | .El |
124 | .Sh RETURN VALUES | |
c24fefdc | 125 | Upon successful completion, the value returned depends on |
931b8415 | 126 | .Fa cmd |
c24fefdc | 127 | as follows: |
931b8415 CL |
128 | .Bl -tag -width F_GETOWNX -offset indent |
129 | .It Dv F_DUPFD | |
130 | A new file descriptor. | |
131 | .It Dv F_GETFD | |
132 | Value of flag (only the low-order bit is defined). | |
133 | .It Dv F_GETFL | |
134 | Value of flags. | |
135 | .It Dv F_GETOWN | |
136 | Value of file descriptor owner. | |
137 | .It other | |
138 | Value other than -1. | |
139 | .El | |
140 | .Pp | |
141 | Otherwise, a value of -1 is returned and | |
142 | .Va errno | |
c24fefdc | 143 | is set to indicate the error. |
931b8415 CL |
144 | .Sh ERRORS |
145 | .Fn Fcntl | |
146 | will fail if: | |
147 | .Bl -tag -width Er | |
148 | .It Bq Er EBADF | |
149 | .Fa Fildes | |
c24fefdc | 150 | is not a valid open file descriptor. |
931b8415 CL |
151 | .It Bq Er EMFILE |
152 | .Fa Cmd | |
153 | is | |
154 | .Dv F_DUPFD | |
155 | and the maximum allowed number of file descriptors are currently | |
c24fefdc | 156 | open. |
931b8415 CL |
157 | .It Bq Er EINVAL |
158 | .Fa Cmd | |
159 | is | |
160 | .Dv F_DUPFD | |
161 | and | |
162 | .Fa arg | |
d4bad45b | 163 | is negative or greater than the maximum allowable number |
c24fefdc | 164 | (see |
931b8415 CL |
165 | .Xr getdtablesize 2 ) . |
166 | .It Bq Er ESRCH | |
167 | .Fa Cmd | |
168 | is | |
169 | .Dv F_SETOWN | |
170 | and | |
cae3bf24 | 171 | the process ID given as argument is not in use. |
931b8415 CL |
172 | .El |
173 | .Sh SEE ALSO | |
174 | .Xr close 2 , | |
175 | .Xr execve 2 , | |
176 | .Xr getdtablesize 2 , | |
177 | .Xr open 2 , | |
178 | .Xr sigvec 2 | |
179 | .Sh BUGS | |
180 | The asynchronous I/O facilities of | |
181 | .Dv FNDELAY | |
182 | and | |
183 | .Dv FASYNC | |
1df601cf | 184 | are currently available only for tty and socket operations. |
931b8415 CL |
185 | .Sh HISTORY |
186 | The | |
187 | .Nm | |
188 | function call appeared in | |
189 | .Bx 4.2 . |