Debian Codegraph @

lib/fcntl.in.h

raw
1 /* Like <fcntl.h>, but with non-working flags defined to 0.
2
3 Copyright (C) 2006-2026 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18 /* written by Paul Eggert */
19
20 #if __GNUC__ >= 3
21 @PRAGMA_SYSTEM_HEADER@
22 #endif
23 @PRAGMA_COLUMNS@
24
25 #if defined __need_system_fcntl_h || defined _@GUARD_PREFIX@_ALREADY_INCLUDING_FCNTL_H
26 /* Special invocation convention:
27 - On Haiku we have a sequence of nested includes
28 <fcntl.h> -> <unistd.h> -> <fcntl.h>
29 In this situation, GNULIB_defined_O_NONBLOCK gets defined before the
30 system's definition of O_NONBLOCK is processed. */
31
32 /* Needed before <sys/stat.h>.
33 May also define off_t to a 64-bit type on native Windows. */
34 #include <sys/types.h>
35 /* On some systems other than glibc, <sys/stat.h> is a prerequisite of
36 <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
37 But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
38 extern "C" { ... } block, which leads to errors in C++ mode with the
39 overridden <sys/stat.h> from gnulib. These errors are known to be gone
40 with g++ version >= 4.3. */
41 #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
42 # include <sys/stat.h>
43 #endif
44 #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
45
46 /* Native Windows platforms declare open(), creat() in <io.h>. */
47 #if (@GNULIB_CREAT@ || @GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
48 && (defined _WIN32 && ! defined __CYGWIN__)
49 # include <io.h>
50 #endif
51
52 #else
53 /* Normal invocation convention. */
54
55 #ifndef _@GUARD_PREFIX@_FCNTL_H
56
57 #define _@GUARD_PREFIX@_ALREADY_INCLUDING_FCNTL_H
58
59 /* Needed before <sys/stat.h>.
60 May also define off_t to a 64-bit type on native Windows.
61 Also defines off64_t on macOS, NetBSD, OpenBSD, MSVC, Cygwin, Haiku. */
62 #include <sys/types.h>
63 /* On some systems other than glibc, <sys/stat.h> is a prerequisite of
64 <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
65 But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
66 extern "C" { ... } block, which leads to errors in C++ mode with the
67 overridden <sys/stat.h> from gnulib. These errors are known to be gone
68 with g++ version >= 4.3. */
69 #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
70 # include <sys/stat.h>
71 #endif
72 /* The include_next requires a split double-inclusion guard. */
73 #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
74
75 /* Native Windows platforms declare open(), creat() in <io.h>. */
76 #if (@GNULIB_CREAT@ || @GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
77 && (defined _WIN32 && ! defined __CYGWIN__)
78 # include <io.h>
79 #endif
80
81 #undef _@GUARD_PREFIX@_ALREADY_INCLUDING_FCNTL_H
82
83 #ifndef _@GUARD_PREFIX@_FCNTL_H
84 #define _@GUARD_PREFIX@_FCNTL_H
85
86 /* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
87 #if !_GL_CONFIG_H_INCLUDED
88 #error "Please include config.h first."
89 #endif
90
91 #ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
92 # include <unistd.h>
93 #endif
94
95
96 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
97
98 /* The definition of _GL_ARG_NONNULL is copied here. */
99
100 /* The definition of _GL_WARN_ON_USE is copied here. */
101
102
103 /* Declare overridden functions. */
104
105 #if @GNULIB_CREAT@
106 # if @REPLACE_CREAT@
107 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
108 # undef creat
109 # define creat rpl_creat
110 # endif
111 _GL_FUNCDECL_RPL (creat, int, (const char *filename, mode_t mode),
112 _GL_ARG_NONNULL ((1)));
113 _GL_CXXALIAS_RPL (creat, int, (const char *filename, mode_t mode));
114 # elif defined _WIN32 && !defined __CYGWIN__
115 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
116 # undef creat
117 # define creat _creat
118 # endif
119 _GL_CXXALIAS_MDA (creat, int, (const char *filename, mode_t mode));
120 # else
121 _GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
122 # endif
123 _GL_CXXALIASWARN (creat);
124 #elif defined GNULIB_POSIXCHECK
125 /* Assume creat is always declared. */
126 _GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - "
127 "use gnulib module creat for portability");
128 #elif @GNULIB_MDA_CREAT@
129 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
130 required. In C++ with GNULIB_NAMESPACE, avoid differences between
131 platforms by defining GNULIB_NAMESPACE::creat always. */
132 # if defined _WIN32 && !defined __CYGWIN__
133 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
134 # undef creat
135 # define creat _creat
136 # endif
137 /* Need to cast, because in mingw the last argument is 'int mode'. */
138 _GL_CXXALIAS_MDA_CAST (creat, int, (const char *filename, mode_t mode));
139 # else
140 _GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
141 # endif
142 _GL_CXXALIASWARN (creat);
143 #endif
144
145 #if @GNULIB_FCNTL@
146 # if @REPLACE_FCNTL@
147 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
148 # undef fcntl
149 # define fcntl rpl_fcntl
150 # endif
151 _GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...), );
152 _GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
153 # if !GNULIB_defined_rpl_fcntl
154 # define GNULIB_defined_rpl_fcntl 1
155 # endif
156 # else
157 # if !@HAVE_FCNTL@
158 _GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...), );
159 # if !GNULIB_defined_fcntl
160 # define GNULIB_defined_fcntl 1
161 # endif
162 # endif
163 _GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
164 # endif
165 _GL_CXXALIASWARN (fcntl);
166 #elif defined GNULIB_POSIXCHECK
167 # if HAVE_RAW_DECL_FCNTL
168 _GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
169 "use gnulib module fcntl for portability");
170 # endif
171 #endif
172
173 #if @GNULIB_OPEN@
174 # if @REPLACE_OPEN@
175 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
176 # undef open
177 # define open rpl_open
178 # endif
179 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...),
180 _GL_ARG_NONNULL ((1)));
181 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
182 # elif defined _WIN32 && !defined __CYGWIN__
183 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
184 # undef open
185 # define open _open
186 # endif
187 _GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
188 # else
189 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
190 # endif
191 /* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
192 default argument. _GL_CXXALIASWARN does not work in this case. */
193 # if !defined __hpux
194 _GL_CXXALIASWARN (open);
195 # endif
196 #elif defined GNULIB_POSIXCHECK
197 /* Assume open is always declared. */
198 _GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
199 "use gnulib module open for portability");
200 #elif @GNULIB_MDA_OPEN@
201 /* On native Windows, map 'open' to '_open', so that -loldnames is not
202 required. In C++ with GNULIB_NAMESPACE, avoid differences between
203 platforms by defining GNULIB_NAMESPACE::open always. */
204 # if defined _WIN32 && !defined __CYGWIN__
205 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
206 # undef open
207 # define open _open
208 # endif
209 /* Need to cast, because in MSVC the parameter list of _open as a C++ function
210 is (const char *, int, int = 0). */
211 _GL_CXXALIAS_MDA_CAST (open, int, (const char *filename, int flags, ...));
212 # else
213 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
214 # endif
215 # if !defined __hpux
216 _GL_CXXALIASWARN (open);
217 # endif
218 #endif
219
220 #if @GNULIB_OPENAT@
221 # if @REPLACE_OPENAT@
222 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
223 # undef openat
224 # define openat rpl_openat
225 # endif
226 _GL_FUNCDECL_RPL (openat, int,
227 (int fd, char const *file, int flags, /* mode_t mode */ ...),
228 _GL_ARG_NONNULL ((2)));
229 _GL_CXXALIAS_RPL (openat, int,
230 (int fd, char const *file, int flags, /* mode_t mode */ ...));
231 # else
232 # if !@HAVE_OPENAT@
233 _GL_FUNCDECL_SYS (openat, int,
234 (int fd, char const *file, int flags, /* mode_t mode */ ...),
235 _GL_ARG_NONNULL ((2)));
236 # endif
237 _GL_CXXALIAS_SYS (openat, int,
238 (int fd, char const *file, int flags, /* mode_t mode */ ...));
239 # endif
240 _GL_CXXALIASWARN (openat);
241 #elif defined GNULIB_POSIXCHECK
242 # if HAVE_RAW_DECL_OPENAT
243 _GL_WARN_ON_USE (openat, "openat is not portable - "
244 "use gnulib module openat for portability");
245 # endif
246 #endif
247
248 #if @GNULIB_OPENAT2@
249 # if !defined RESOLVE_NO_XDEV && defined __has_include
250 # if __has_include (<linux/openat2.h>)
251 # include <linux/openat2.h>
252 # endif
253 # endif
254 # ifndef RESOLVE_NO_XDEV
255 struct open_how
256 {
257 # ifdef __UINT64_TYPE__
258 __UINT64_TYPE__ flags, mode, resolve;
259 # else
260 unsigned long long int flags, mode, resolve;
261 # endif
262 };
263 # define RESOLVE_NO_XDEV 0x01
264 # define RESOLVE_NO_MAGICLINKS 0x02
265 # define RESOLVE_NO_SYMLINKS 0x04
266 # define RESOLVE_BENEATH 0x08
267 # define RESOLVE_IN_ROOT 0x10
268 # define RESOLVE_CACHED 0x20
269 # endif
270
271 # if !@HAVE_OPENAT2@
272 _GL_FUNCDECL_SYS (openat2, int,
273 (int fd, char const *file, struct open_how const *how,
274 size_t size),
275 _GL_ARG_NONNULL ((2, 3)));
276 # endif
277 _GL_CXXALIAS_SYS (openat2, int,
278 (int fd, char const *file, struct open_how const *how,
279 size_t size));
280 _GL_CXXALIASWARN (openat2);
281 #elif defined GNULIB_POSIXCHECK
282 # if HAVE_RAW_DECL_OPENAT2
283 _GL_WARN_ON_USE (openat2, "openat2 is not portable - "
284 "use gnulib module openat2 for portability");
285 # endif
286 #endif
287
288 /* Fix up the FD_* macros, only known to be missing on mingw. */
289
290 #ifndef FD_CLOEXEC
291 # define FD_CLOEXEC 1
292 #endif
293
294 /* Fix up the supported F_* macros. Intentionally leave other F_*
295 macros undefined. Only known to be missing on mingw. */
296
297 #ifndef F_DUPFD_CLOEXEC
298 # define F_DUPFD_CLOEXEC 0x40000000
299 /* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
300 # define GNULIB_defined_F_DUPFD_CLOEXEC 1
301 #else
302 # define GNULIB_defined_F_DUPFD_CLOEXEC 0
303 #endif
304
305 #ifndef F_DUPFD
306 # define F_DUPFD 1
307 #endif
308
309 #ifndef F_GETFD
310 # define F_GETFD 2
311 #endif
312
313 /* Fix up the O_* macros. */
314
315 /* AIX 7.1 with XL C 12.1 defines O_CLOEXEC, O_NOFOLLOW, and O_TTY_INIT
316 to values outside 'int' range, so omit these misdefinitions.
317 But avoid namespace pollution on non-AIX systems. */
318 #ifdef _AIX
319 # include <limits.h>
320 # if defined O_CLOEXEC && ! (INT_MIN <= O_CLOEXEC && O_CLOEXEC <= INT_MAX)
321 # undef O_CLOEXEC
322 # endif
323 # if defined O_NOFOLLOW && ! (INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX)
324 # undef O_NOFOLLOW
325 # endif
326 # if defined O_TTY_INIT && ! (INT_MIN <= O_TTY_INIT && O_TTY_INIT <= INT_MAX)
327 # undef O_TTY_INIT
328 # endif
329 #endif
330
331 #if !defined O_CLOEXEC && defined O_NOINHERIT
332 /* Mingw spells it 'O_NOINHERIT'. */
333 # define O_CLOEXEC O_NOINHERIT
334 #endif
335
336 #ifndef O_CLOEXEC
337 # define O_CLOEXEC 0x40000000 /* Try to not collide with system O_* flags. */
338 # define GNULIB_defined_O_CLOEXEC 1
339 #else
340 # define GNULIB_defined_O_CLOEXEC 0
341 #endif
342
343 #ifndef O_DIRECT
344 # define O_DIRECT 0
345 #endif
346
347 #ifndef O_DIRECTORY
348 # define O_DIRECTORY 0x20000000 /* Try to not collide with system O_* flags. */
349 #endif
350
351 #ifndef O_DSYNC
352 # define O_DSYNC 0
353 #endif
354
355 #ifndef O_EXEC
356 # define O_EXEC O_RDONLY /* This is often close enough in older systems. */
357 #endif
358
359 #ifndef O_IGNORE_CTTY
360 # define O_IGNORE_CTTY 0
361 #endif
362
363 #ifndef O_NDELAY
364 # define O_NDELAY 0
365 #endif
366
367 #ifndef O_NOATIME
368 # define O_NOATIME 0
369 #endif
370
371 #ifndef O_NONBLOCK
372 # define O_NONBLOCK O_NDELAY
373 #endif
374
375 /* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
376 value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
377 or to 0 as fallback. */
378 #if @GNULIB_NONBLOCKING@
379 # if O_NONBLOCK
380 # define GNULIB_defined_O_NONBLOCK 0
381 # else
382 # define GNULIB_defined_O_NONBLOCK 1
383 # undef O_NONBLOCK
384 # define O_NONBLOCK 0x40000000
385 # endif
386 #endif
387
388 #ifndef O_NOCTTY
389 # define O_NOCTTY 0
390 #endif
391
392 #ifndef O_NOFOLLOW
393 # define O_NOFOLLOW 0
394 #endif
395
396 #ifndef O_NOLINK
397 # define O_NOLINK 0
398 #endif
399
400 #ifndef O_NOLINKS
401 # define O_NOLINKS 0
402 #endif
403
404 #ifndef O_NOTRANS
405 # define O_NOTRANS 0
406 #endif
407
408 #ifndef O_RSYNC
409 # define O_RSYNC 0
410 #endif
411
412 #if defined O_SEARCH && defined O_PATH && O_SEARCH == O_PATH
413 # undef O_SEARCH /* musl mistakenly #defines O_SEARCH to O_PATH. */
414 #endif
415
416 #ifndef O_SEARCH
417 # define O_SEARCH O_RDONLY /* Often close enough in non-POSIX systems. */
418 #endif
419
420 #ifndef O_SYNC
421 # define O_SYNC 0
422 #endif
423
424 #ifndef O_TTY_INIT
425 # define O_TTY_INIT 0
426 #endif
427
428 #if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
429 # undef O_ACCMODE
430 # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
431 #endif
432
433 /* For systems that distinguish between text and binary I/O.
434 O_BINARY is usually declared in fcntl.h */
435 #if !defined O_BINARY && defined _O_BINARY
436 /* For MSC-compatible compilers. */
437 # define O_BINARY _O_BINARY
438 # define O_TEXT _O_TEXT
439 #endif
440
441 #if defined __BEOS__ || defined __HAIKU__
442 /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
443 # undef O_BINARY
444 # undef O_TEXT
445 #endif
446
447 #ifndef O_BINARY
448 # define O_BINARY 0
449 # define O_TEXT 0
450 #endif
451
452 /* Fix up the AT_* macros. */
453
454 /* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
455 value exceeds INT_MAX, so its use as an int doesn't conform to the
456 C standard, and GCC and Sun C complain in some cases. If the bug
457 is present, undef AT_FDCWD here, so it can be redefined below. */
458 #if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
459 # undef AT_FDCWD
460 #endif
461
462 /* Use the same bit pattern as Solaris 9, but with the proper
463 signedness. The bit pattern is important, in case this actually is
464 Solaris with the above workaround. */
465 #ifndef AT_FDCWD
466 # define AT_FDCWD (-3041965)
467 #endif
468
469 /* Use the same values as Solaris 9. This shouldn't matter, but
470 there's no real reason to differ. */
471 #ifndef AT_SYMLINK_NOFOLLOW
472 # define AT_SYMLINK_NOFOLLOW 4096
473 #endif
474
475 #ifndef AT_REMOVEDIR
476 # define AT_REMOVEDIR 1
477 #endif
478
479 /* Solaris 9 lacks these two, so just pick unique values. */
480 #ifndef AT_SYMLINK_FOLLOW
481 # define AT_SYMLINK_FOLLOW 2
482 #endif
483
484 #ifndef AT_EACCESS
485 # define AT_EACCESS 4
486 #endif
487
488 /* Ignore this flag if not supported. */
489 #ifndef AT_NO_AUTOMOUNT
490 # define AT_NO_AUTOMOUNT 0
491 #endif
492
493 /* errno when openat+O_NOFOLLOW fails because the file is a symlink. */
494 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __DragonFly__
495 # define _GL_OPENAT_ESYMLINK EMLINK
496 #elif defined __NetBSD__
497 # define _GL_OPENAT_ESYMLINK EFTYPE
498 #else
499 # define _GL_OPENAT_ESYMLINK ELOOP
500 #endif
501
502 #endif /* _@GUARD_PREFIX@_FCNTL_H */
503 #endif /* _@GUARD_PREFIX@_FCNTL_H */
504 #endif