Debian Codegraph @

lib/fcntl.in.h

raw
1 /* Like <fcntl.h>, but with non-working flags defined to 0.
2
3 Copyright (C) 2006-2025 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 # undef creat
126 /* Assume creat is always declared. */
127 _GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - "
128 "use gnulib module creat for portability");
129 #elif @GNULIB_MDA_CREAT@
130 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
131 required. In C++ with GNULIB_NAMESPACE, avoid differences between
132 platforms by defining GNULIB_NAMESPACE::creat always. */
133 # if defined _WIN32 && !defined __CYGWIN__
134 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
135 # undef creat
136 # define creat _creat
137 # endif
138 /* Need to cast, because in mingw the last argument is 'int mode'. */
139 _GL_CXXALIAS_MDA_CAST (creat, int, (const char *filename, mode_t mode));
140 # else
141 _GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
142 # endif
143 _GL_CXXALIASWARN (creat);
144 #endif
145
146 #if @GNULIB_FCNTL@
147 # if @REPLACE_FCNTL@
148 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
149 # undef fcntl
150 # define fcntl rpl_fcntl
151 # endif
152 _GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...), );
153 _GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
154 # if !GNULIB_defined_rpl_fcntl
155 # define GNULIB_defined_rpl_fcntl 1
156 # endif
157 # else
158 # if !@HAVE_FCNTL@
159 _GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...), );
160 # if !GNULIB_defined_fcntl
161 # define GNULIB_defined_fcntl 1
162 # endif
163 # endif
164 _GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
165 # endif
166 _GL_CXXALIASWARN (fcntl);
167 #elif defined GNULIB_POSIXCHECK
168 # undef fcntl
169 # if HAVE_RAW_DECL_FCNTL
170 _GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
171 "use gnulib module fcntl for portability");
172 # endif
173 #endif
174
175 #if @GNULIB_OPEN@
176 # if @REPLACE_OPEN@
177 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
178 # undef open
179 # define open rpl_open
180 # endif
181 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...),
182 _GL_ARG_NONNULL ((1)));
183 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
184 # elif defined _WIN32 && !defined __CYGWIN__
185 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
186 # undef open
187 # define open _open
188 # endif
189 _GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
190 # else
191 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
192 # endif
193 /* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
194 default argument. _GL_CXXALIASWARN does not work in this case. */
195 # if !defined __hpux
196 _GL_CXXALIASWARN (open);
197 # endif
198 #elif defined GNULIB_POSIXCHECK
199 # undef open
200 /* Assume open is always declared. */
201 _GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
202 "use gnulib module open for portability");
203 #elif @GNULIB_MDA_OPEN@
204 /* On native Windows, map 'open' to '_open', so that -loldnames is not
205 required. In C++ with GNULIB_NAMESPACE, avoid differences between
206 platforms by defining GNULIB_NAMESPACE::open always. */
207 # if defined _WIN32 && !defined __CYGWIN__
208 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
209 # undef open
210 # define open _open
211 # endif
212 _GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
213 # else
214 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
215 # endif
216 # if !defined __hpux
217 _GL_CXXALIASWARN (open);
218 # endif
219 #endif
220
221 #if @GNULIB_OPENAT@
222 # if @REPLACE_OPENAT@
223 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224 # undef openat
225 # define openat rpl_openat
226 # endif
227 _GL_FUNCDECL_RPL (openat, int,
228 (int fd, char const *file, int flags, /* mode_t mode */ ...),
229 _GL_ARG_NONNULL ((2)));
230 _GL_CXXALIAS_RPL (openat, int,
231 (int fd, char const *file, int flags, /* mode_t mode */ ...));
232 # else
233 # if !@HAVE_OPENAT@
234 _GL_FUNCDECL_SYS (openat, int,
235 (int fd, char const *file, int flags, /* mode_t mode */ ...),
236 _GL_ARG_NONNULL ((2)));
237 # endif
238 _GL_CXXALIAS_SYS (openat, int,
239 (int fd, char const *file, int flags, /* mode_t mode */ ...));
240 # endif
241 _GL_CXXALIASWARN (openat);
242 #elif defined GNULIB_POSIXCHECK
243 # undef openat
244 # if HAVE_RAW_DECL_OPENAT
245 _GL_WARN_ON_USE (openat, "openat is not portable - "
246 "use gnulib module openat for portability");
247 # endif
248 #endif
249
250
251 /* Fix up the FD_* macros, only known to be missing on mingw. */
252
253 #ifndef FD_CLOEXEC
254 # define FD_CLOEXEC 1
255 #endif
256
257 /* Fix up the supported F_* macros. Intentionally leave other F_*
258 macros undefined. Only known to be missing on mingw. */
259
260 #ifndef F_DUPFD_CLOEXEC
261 # define F_DUPFD_CLOEXEC 0x40000000
262 /* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
263 # define GNULIB_defined_F_DUPFD_CLOEXEC 1
264 #else
265 # define GNULIB_defined_F_DUPFD_CLOEXEC 0
266 #endif
267
268 #ifndef F_DUPFD
269 # define F_DUPFD 1
270 #endif
271
272 #ifndef F_GETFD
273 # define F_GETFD 2
274 #endif
275
276 /* Fix up the O_* macros. */
277
278 /* AIX 7.1 with XL C 12.1 defines O_CLOEXEC, O_NOFOLLOW, and O_TTY_INIT
279 to values outside 'int' range, so omit these misdefinitions.
280 But avoid namespace pollution on non-AIX systems. */
281 #ifdef _AIX
282 # include <limits.h>
283 # if defined O_CLOEXEC && ! (INT_MIN <= O_CLOEXEC && O_CLOEXEC <= INT_MAX)
284 # undef O_CLOEXEC
285 # endif
286 # if defined O_NOFOLLOW && ! (INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX)
287 # undef O_NOFOLLOW
288 # endif
289 # if defined O_TTY_INIT && ! (INT_MIN <= O_TTY_INIT && O_TTY_INIT <= INT_MAX)
290 # undef O_TTY_INIT
291 # endif
292 #endif
293
294 #if !defined O_DIRECT && defined O_DIRECTIO
295 /* Tru64 spells it 'O_DIRECTIO'. */
296 # define O_DIRECT O_DIRECTIO
297 #endif
298
299 #if !defined O_CLOEXEC && defined O_NOINHERIT
300 /* Mingw spells it 'O_NOINHERIT'. */
301 # define O_CLOEXEC O_NOINHERIT
302 #endif
303
304 #ifndef O_CLOEXEC
305 # define O_CLOEXEC 0x40000000 /* Try to not collide with system O_* flags. */
306 # define GNULIB_defined_O_CLOEXEC 1
307 #else
308 # define GNULIB_defined_O_CLOEXEC 0
309 #endif
310
311 #ifndef O_DIRECT
312 # define O_DIRECT 0
313 #endif
314
315 #ifndef O_DIRECTORY
316 # define O_DIRECTORY 0
317 #endif
318
319 #ifndef O_DSYNC
320 # define O_DSYNC 0
321 #endif
322
323 #ifndef O_EXEC
324 # define O_EXEC O_RDONLY /* This is often close enough in older systems. */
325 #endif
326
327 #ifndef O_IGNORE_CTTY
328 # define O_IGNORE_CTTY 0
329 #endif
330
331 #ifndef O_NDELAY
332 # define O_NDELAY 0
333 #endif
334
335 #ifndef O_NOATIME
336 # define O_NOATIME 0
337 #endif
338
339 #ifndef O_NONBLOCK
340 # define O_NONBLOCK O_NDELAY
341 #endif
342
343 /* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
344 value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
345 or to 0 as fallback. */
346 #if @GNULIB_NONBLOCKING@
347 # if O_NONBLOCK
348 # define GNULIB_defined_O_NONBLOCK 0
349 # else
350 # define GNULIB_defined_O_NONBLOCK 1
351 # undef O_NONBLOCK
352 # define O_NONBLOCK 0x40000000
353 # endif
354 #endif
355
356 #ifndef O_NOCTTY
357 # define O_NOCTTY 0
358 #endif
359
360 #ifndef O_NOFOLLOW
361 # define O_NOFOLLOW 0
362 #endif
363
364 #ifndef O_NOLINK
365 # define O_NOLINK 0
366 #endif
367
368 #ifndef O_NOLINKS
369 # define O_NOLINKS 0
370 #endif
371
372 #ifndef O_NOTRANS
373 # define O_NOTRANS 0
374 #endif
375
376 #ifndef O_RSYNC
377 # define O_RSYNC 0
378 #endif
379
380 #if defined O_SEARCH && defined O_PATH && O_SEARCH == O_PATH
381 # undef O_SEARCH /* musl mistakenly #defines O_SEARCH to O_PATH. */
382 #endif
383
384 #ifndef O_SEARCH
385 # define O_SEARCH O_RDONLY /* Often close enough in non-POSIX systems. */
386 #endif
387
388 #ifndef O_SYNC
389 # define O_SYNC 0
390 #endif
391
392 #ifndef O_TTY_INIT
393 # define O_TTY_INIT 0
394 #endif
395
396 #if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
397 # undef O_ACCMODE
398 # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
399 #endif
400
401 /* For systems that distinguish between text and binary I/O.
402 O_BINARY is usually declared in fcntl.h */
403 #if !defined O_BINARY && defined _O_BINARY
404 /* For MSC-compatible compilers. */
405 # define O_BINARY _O_BINARY
406 # define O_TEXT _O_TEXT
407 #endif
408
409 #if defined __BEOS__ || defined __HAIKU__
410 /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
411 # undef O_BINARY
412 # undef O_TEXT
413 #endif
414
415 #ifndef O_BINARY
416 # define O_BINARY 0
417 # define O_TEXT 0
418 #endif
419
420 /* Fix up the AT_* macros. */
421
422 /* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
423 value exceeds INT_MAX, so its use as an int doesn't conform to the
424 C standard, and GCC and Sun C complain in some cases. If the bug
425 is present, undef AT_FDCWD here, so it can be redefined below. */
426 #if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
427 # undef AT_FDCWD
428 #endif
429
430 /* Use the same bit pattern as Solaris 9, but with the proper
431 signedness. The bit pattern is important, in case this actually is
432 Solaris with the above workaround. */
433 #ifndef AT_FDCWD
434 # define AT_FDCWD (-3041965)
435 #endif
436
437 /* Use the same values as Solaris 9. This shouldn't matter, but
438 there's no real reason to differ. */
439 #ifndef AT_SYMLINK_NOFOLLOW
440 # define AT_SYMLINK_NOFOLLOW 4096
441 #endif
442
443 #ifndef AT_REMOVEDIR
444 # define AT_REMOVEDIR 1
445 #endif
446
447 /* Solaris 9 lacks these two, so just pick unique values. */
448 #ifndef AT_SYMLINK_FOLLOW
449 # define AT_SYMLINK_FOLLOW 2
450 #endif
451
452 #ifndef AT_EACCESS
453 # define AT_EACCESS 4
454 #endif
455
456 /* Ignore this flag if not supported. */
457 #ifndef AT_NO_AUTOMOUNT
458 # define AT_NO_AUTOMOUNT 0
459 #endif
460
461 #endif /* _@GUARD_PREFIX@_FCNTL_H */
462 #endif /* _@GUARD_PREFIX@_FCNTL_H */
463 #endif