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

NAME

12       fcntl.h — file control options
13

SYNOPSIS

15       #include <fcntl.h>
16

DESCRIPTION

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

APPLICATION USAGE

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

RATIONALE

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

FUTURE DIRECTIONS

241       None.
242

SEE ALSO

244       <stdio.h>, <sys_stat.h>, <sys_types.h>, <unistd.h>
245
246       The  System  Interfaces volume of POSIX.1‐2017, creat(), exec, fcntl(),
247       futimens(), open(), posix_fadvise(), posix_fallocate(), posix_madvise()
248
250       Portions of this text are reprinted and reproduced in  electronic  form
251       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
252       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
253       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
254       Electrical and Electronics Engineers, Inc and The Open Group.   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.opengroup.org/unix/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                  2017                          fcntl.h(0P)
Impressum