1fcntl.h(0P)                POSIX Programmer's Manual               fcntl.h(0P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       fcntl.h — file control options
14

SYNOPSIS

16       #include <fcntl.h>
17

DESCRIPTION

19       The <fcntl.h> header shall define the following symbolic constants  for
20       the cmd argument used by fcntl().  The values shall be unique and shall
21       be suitable for use in #if preprocessing directives.
22
23       F_DUPFD     Duplicate file descriptor.
24
25       F_DUPFD_CLOEXEC
26                   Duplicate  file  descriptor  with  the  close-on-exec  flag
27                   FD_CLOEXEC set.
28
29       F_GETFD     Get file descriptor flags.
30
31       F_SETFD     Set file descriptor flags.
32
33       F_GETFL     Get file status flags and file access modes.
34
35       F_SETFL     Set file status flags.
36
37       F_GETLK     Get record locking information.
38
39       F_SETLK     Set record locking information.
40
41       F_SETLKW    Set record locking information; wait if blocked.
42
43       F_GETOWN    Get process or process group ID to receive SIGURG signals.
44
45       F_SETOWN    Set process or process group ID to receive SIGURG signals.
46
47       The  <fcntl.h> header shall define the following symbolic constant used
48       for the fcntl() file descriptor flags, which shall be suitable for  use
49       in #if preprocessing directives.
50
51       FD_CLOEXEC  Close  the file descriptor upon execution of an exec family
52                   function.
53
54       The <fcntl.h> header shall also define the following symbolic constants
55       for the l_type argument used for record locking with fcntl().  The val‐
56       ues shall be unique and shall be suitable for use in #if  preprocessing
57       directives.
58
59       F_RDLCK     Shared or read lock.
60
61       F_UNLCK     Unlock.
62
63       F_WRLCK     Exclusive or write lock.
64
65       The  <fcntl.h>  header  shall  define  the  values  used  for l_whence,
66       SEEK_SET, SEEK_CUR, and SEEK_END as described in <stdio.h>.
67
68       The <fcntl.h> header shall define the following symbolic  constants  as
69       file  creation flags for use in the oflag value to open() and openat().
70       The values shall be bitwise-distinct and shall be suitable for  use  in
71       #if preprocessing directives.
72
73       O_CLOEXEC   The  FD_CLOEXEC  flag  associated  with  the new descriptor
74                   shall be set to close the file descriptor upon execution of
75                   an exec family function.
76
77       O_CREAT     Create file if it does not exist.
78
79       O_DIRECTORY Fail if not a directory.
80
81       O_EXCL      Exclusive use flag.
82
83       O_NOCTTY    Do not assign controlling terminal.
84
85       O_NOFOLLOW  Do not follow symbolic links.
86
87       O_TRUNC     Truncate flag.
88
89       O_TTY_INIT  Set  the  termios  structure terminal parameters to a state
90                   that provides conforming behavior; see Section 11.2, Param‐
91                   eters that Can be Set.
92
93       The  O_TTY_INIT  flag  can have the value zero and in this case it need
94       not be bitwise-distinct from the other flags.
95
96       The <fcntl.h> header shall define the following symbolic constants  for
97       use as file status flags for open(), openat(), and fcntl().  The values
98       shall be suitable for use in #if preprocessing directives.
99
100       O_APPEND    Set append mode.
101
102       O_DSYNC     Write according to synchronized I/O data integrity  comple‐
103                   tion.
104
105       O_NONBLOCK  Non-blocking mode.
106
107       O_RSYNC     Synchronized read I/O operations.
108
109       O_SYNC      Write  according to synchronized I/O file integrity comple‐
110                   tion.
111
112       The <fcntl.h> header shall define the following symbolic  constant  for
113       use  as the mask for file access modes. The value shall be suitable for
114       use in #if preprocessing directives.
115
116       O_ACCMODE   Mask for file access modes.
117
118       The <fcntl.h> header shall define the following symbolic constants  for
119       use  as  the  file access modes for open(), openat(), and fcntl().  The
120       values shall be unique, except that O_EXEC and O_SEARCH may have  equal
121       values.  The  values  shall  be  suitable  for use in #if preprocessing
122       directives.
123
124       O_EXEC      Open for execute only (non-directory files). The result  is
125                   unspecified if this flag is applied to a directory.
126
127       O_RDONLY    Open for reading only.
128
129       O_RDWR      Open for reading and writing.
130
131       O_SEARCH    Open  directory  for search only. The result is unspecified
132                   if this flag is applied to a non-directory file.
133
134       O_WRONLY    Open for writing only.
135
136       The <fcntl.h> header shall define the symbolic constants for file modes
137       for use as values of mode_t as described in <sys/stat.h>.
138
139       The  <fcntl.h> header shall define the following symbolic constant as a
140       special value used in place of a file descriptor for  the  *at()  func‐
141       tions which take a directory file descriptor as a parameter:
142
143       AT_FDCWD    Use  the  current working directory to determine the target
144                   of relative file paths.
145
146       The <fcntl.h> header shall define the following symbolic constant as  a
147       value for the flag used by faccessat():
148
149       AT_EACCESS  Check access using effective user and group ID.
150
151       The  <fcntl.h> header shall define the following symbolic constant as a
152       value for the flag used by fstatat(), fchmodat(), fchownat(), and  uti‐
153       mensat():
154
155       AT_SYMLINK_NOFOLLOW
156                   Do not follow symbolic links.
157
158       The  <fcntl.h> header shall define the following symbolic constant as a
159       value for the flag used by linkat():
160
161       AT_SYMLINK_FOLLOW
162                   Follow symbolic link.
163
164       The <fcntl.h> header shall define the following symbolic constant as  a
165       value for the flag used by unlinkat():
166
167       AT_REMOVEDIR
168                   Remove directory instead of file.
169
170       The  <fcntl.h> header shall define the following symbolic constants for
171       the advice argument used by posix_fadvise():
172
173       POSIX_FADV_DONTNEED
174             The application expects that it will  not  access  the  specified
175             data in the near future.
176
177       POSIX_FADV_NOREUSE
178             The  application  expects  to  access the specified data once and
179             then not reuse it thereafter.
180
181       POSIX_FADV_NORMAL
182             The application has no  advice  to  give  on  its  behavior  with
183             respect  to  the specified data. It is the default characteristic
184             if no advice is given for an open file.
185
186       POSIX_FADV_RANDOM
187             The application expects to access the specified data in a  random
188             order.
189
190       POSIX_FADV_SEQUENTIAL
191             The application expects to access the specified data sequentially
192             from lower offsets to higher offsets.
193
194       POSIX_FADV_WILLNEED
195             The application expects to access the specified data in the  near
196             future.
197
198       The <fcntl.h> header shall define the flock structure describing a file
199       lock. It shall include the following members:
200
201           short  l_type   Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
202           short  l_whence Flag for starting offset.
203           off_t  l_start  Relative offset in bytes.
204           off_t  l_len    Size; if 0 then until EOF.
205           pid_t  l_pid    Process ID of the process holding the lock; returned with F_GETLK.
206
207       The <fcntl.h> header shall define the mode_t, off_t, and pid_t types as
208       described in <sys/types.h>.
209
210       The following shall be declared as functions and may also be defined as
211       macros. Function prototypes shall be provided.
212
213           int  creat(const char *, mode_t);
214           int  fcntl(int, int, ...);
215           int  open(const char *, int, ...);
216           int  openat(int, const char *, int, ...);
217           int  posix_fadvise(int, off_t, off_t, int);
218           int  posix_fallocate(int, off_t, off_t);
219
220       Inclusion of the <fcntl.h> header may also  make  visible  all  symbols
221       from <sys/stat.h> and <unistd.h>.
222
223       The following sections are informative.
224

APPLICATION USAGE

226       Although  no  existing  implementation  defines  AT_SYMLINK_FOLLOW  and
227       AT_SYMLINK_NOFOLLOW as the same numeric value,  POSIX.1‐2008  does  not
228       prohibit  that  as  the two constants are not used with the same inter‐
229       faces.
230

RATIONALE

232       While many of the symbolic constants introduced in the <fcntl.h> header
233       do  not  strictly need to be used in #if preprocessor directives, wide‐
234       spread historic practice has defined them as macros that are usable  in
235       such  constructs,  and  examination  of existing applications has shown
236       that they are occasionally used in such a way. Therefore it was decided
237       to retain this requirement on an implementation in POSIX.1‐2008.
238

FUTURE DIRECTIONS

240       None.
241

SEE ALSO

243       <stdio.h>, <sys_stat.h>, <sys_types.h>, <unistd.h>
244
245       The  System  Interfaces volume of POSIX.1‐2008, creat(), exec, fcntl(),
246       futimens(), open(), posix_fadvise(), posix_fallocate(), posix_madvise()
247
249       Portions of this text are reprinted and reproduced in  electronic  form
250       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
251       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
252       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
253       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
254       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
255       event of any discrepancy between this version and the original IEEE and
256       The  Open Group Standard, the original IEEE and The Open Group Standard
257       is the referee document. The original Standard can be  obtained  online
258       at http://www.unix.org/online.html .
259
260       Any  typographical  or  formatting  errors that appear in this page are
261       most likely to have been introduced during the conversion of the source
262       files  to  man page format. To report such errors, see https://www.ker
263       nel.org/doc/man-pages/reporting_bugs.html .
264
265
266
267IEEE/The Open Group                  2013                          fcntl.h(0P)
Impressum