1 /* Like <fcntl.h>, but with non-working flags defined to 0.
3 Copyright (C) 2006-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
18 /* written by Paul Eggert */
21 @PRAGMA_SYSTEM_HEADER@
25 #if defined __need_system_fcntl_h
26 /* Special invocation convention. */
28 /* Needed before <sys/stat.h>.
29 May also define off_t to a 64-bit type on native Windows. */
30 #include <sys/types.h>
31 /* On some systems other than glibc, <sys/stat.h> is a prerequisite of
32 <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
33 But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
34 extern "C" { ... } block, which leads to errors in C++ mode with the
35 overridden <sys/stat.h> from gnulib. These errors are known to be gone
36 with g++ version >= 4.3. */
37 #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
38 # include <sys/stat.h>
40 #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
42 /* Native Windows platforms declare open(), creat() in <io.h>. */
43 #if (@GNULIB_CREAT@ || @GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
44 && (defined _WIN32 && ! defined __CYGWIN__)
49 /* Normal invocation convention. */
51 #ifndef _@GUARD_PREFIX@_FCNTL_H
53 /* Needed before <sys/stat.h>.
54 May also define off_t to a 64-bit type on native Windows. */
55 #include <sys/types.h>
56 /* On some systems other than glibc, <sys/stat.h> is a prerequisite of
57 <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
58 But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
59 extern "C" { ... } block, which leads to errors in C++ mode with the
60 overridden <sys/stat.h> from gnulib. These errors are known to be gone
61 with g++ version >= 4.3. */
62 #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
63 # include <sys/stat.h>
65 /* The include_next requires a split double-inclusion guard. */
66 #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
68 /* Native Windows platforms declare open(), creat() in <io.h>. */
69 #if (@GNULIB_CREAT@ || @GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
70 && (defined _WIN32 && ! defined __CYGWIN__)
74 #ifndef _@GUARD_PREFIX@_FCNTL_H
75 #define _@GUARD_PREFIX@_FCNTL_H
77 /* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
78 #if !_GL_CONFIG_H_INCLUDED
79 #error "Please include config.h first."
82 #ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
87 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
89 /* The definition of _GL_ARG_NONNULL is copied here. */
91 /* The definition of _GL_WARN_ON_USE is copied here. */
94 /* Declare overridden functions. */
98 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
100 # define creat rpl_creat
102 _GL_FUNCDECL_RPL (creat
, int, (const char *filename
, mode_t mode
)
103 _GL_ARG_NONNULL ((1)));
104 _GL_CXXALIAS_RPL (creat
, int, (const char *filename
, mode_t mode
));
105 # elif defined _WIN32 && !defined __CYGWIN__
106 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
108 # define creat _creat
110 _GL_CXXALIAS_MDA (creat
, int, (const char *filename
, mode_t mode
));
112 _GL_CXXALIAS_SYS (creat
, int, (const char *filename
, mode_t mode
));
114 _GL_CXXALIASWARN (creat
);
115 #elif defined GNULIB_POSIXCHECK
117 /* Assume creat is always declared. */
118 _GL_WARN_ON_USE (creat
, "creat is not always POSIX compliant - "
119 "use gnulib module creat for portability");
120 #elif @GNULIB_MDA_CREAT@
121 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
122 required. In C++ with GNULIB_NAMESPACE, avoid differences between
123 platforms by defining GNULIB_NAMESPACE::creat always. */
124 # if defined _WIN32 && !defined __CYGWIN__
125 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
127 # define creat _creat
129 /* Need to cast, because in mingw the last argument is 'int mode'. */
130 _GL_CXXALIAS_MDA_CAST (creat
, int, (const char *filename
, mode_t mode
));
132 _GL_CXXALIAS_SYS (creat
, int, (const char *filename
, mode_t mode
));
134 _GL_CXXALIASWARN (creat
);
139 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
141 # define fcntl rpl_fcntl
143 _GL_FUNCDECL_RPL (fcntl
, int, (int fd
, int action
, ...));
144 _GL_CXXALIAS_RPL (fcntl
, int, (int fd
, int action
, ...));
145 # if !GNULIB_defined_rpl_fcntl
146 # define GNULIB_defined_rpl_fcntl 1
150 _GL_FUNCDECL_SYS (fcntl
, int, (int fd
, int action
, ...));
151 # if !GNULIB_defined_fcntl
152 # define GNULIB_defined_fcntl 1
155 _GL_CXXALIAS_SYS (fcntl
, int, (int fd
, int action
, ...));
157 _GL_CXXALIASWARN (fcntl
);
158 #elif defined GNULIB_POSIXCHECK
160 # if HAVE_RAW_DECL_FCNTL
161 _GL_WARN_ON_USE (fcntl
, "fcntl is not always POSIX compliant - "
162 "use gnulib module fcntl for portability");
168 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
170 # define open rpl_open
172 _GL_FUNCDECL_RPL (open
, int, (const char *filename
, int flags
, ...)
173 _GL_ARG_NONNULL ((1)));
174 _GL_CXXALIAS_RPL (open
, int, (const char *filename
, int flags
, ...));
175 # elif defined _WIN32 && !defined __CYGWIN__
176 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
180 _GL_CXXALIAS_MDA (open
, int, (const char *filename
, int flags
, ...));
182 _GL_CXXALIAS_SYS (open
, int, (const char *filename
, int flags
, ...));
184 /* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
185 default argument. _GL_CXXALIASWARN does not work in this case. */
187 _GL_CXXALIASWARN (open
);
189 #elif defined GNULIB_POSIXCHECK
191 /* Assume open is always declared. */
192 _GL_WARN_ON_USE (open
, "open is not always POSIX compliant - "
193 "use gnulib module open for portability");
194 #elif @GNULIB_MDA_OPEN@
195 /* On native Windows, map 'open' to '_open', so that -loldnames is not
196 required. In C++ with GNULIB_NAMESPACE, avoid differences between
197 platforms by defining GNULIB_NAMESPACE::open always. */
198 # if defined _WIN32 && !defined __CYGWIN__
199 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
203 _GL_CXXALIAS_MDA (open
, int, (const char *filename
, int flags
, ...));
205 _GL_CXXALIAS_SYS (open
, int, (const char *filename
, int flags
, ...));
208 _GL_CXXALIASWARN (open
);
213 # if @REPLACE_OPENAT@
214 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
216 # define openat rpl_openat
218 _GL_FUNCDECL_RPL (openat
, int,
219 (int fd
, char const *file
, int flags
, /* mode_t mode */ ...)
220 _GL_ARG_NONNULL ((2)));
221 _GL_CXXALIAS_RPL (openat
, int,
222 (int fd
, char const *file
, int flags
, /* mode_t mode */ ...));
225 _GL_FUNCDECL_SYS (openat
, int,
226 (int fd
, char const *file
, int flags
, /* mode_t mode */ ...)
227 _GL_ARG_NONNULL ((2)));
229 _GL_CXXALIAS_SYS (openat
, int,
230 (int fd
, char const *file
, int flags
, /* mode_t mode */ ...));
232 _GL_CXXALIASWARN (openat
);
233 #elif defined GNULIB_POSIXCHECK
235 # if HAVE_RAW_DECL_OPENAT
236 _GL_WARN_ON_USE (openat
, "openat is not portable - "
237 "use gnulib module openat for portability");
242 /* Fix up the FD_* macros, only known to be missing on mingw. */
245 # define FD_CLOEXEC 1
248 /* Fix up the supported F_* macros. Intentionally leave other F_*
249 macros undefined. Only known to be missing on mingw. */
251 #ifndef F_DUPFD_CLOEXEC
252 # define F_DUPFD_CLOEXEC 0x40000000
253 /* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
254 # define GNULIB_defined_F_DUPFD_CLOEXEC 1
256 # define GNULIB_defined_F_DUPFD_CLOEXEC 0
267 /* Fix up the O_* macros. */
269 /* AIX 7.1 with XL C 12.1 defines O_CLOEXEC, O_NOFOLLOW, and O_TTY_INIT
270 to values outside 'int' range, so omit these misdefinitions.
271 But avoid namespace pollution on non-AIX systems. */
274 # if defined O_CLOEXEC && ! (INT_MIN <= O_CLOEXEC && O_CLOEXEC <= INT_MAX)
277 # if defined O_NOFOLLOW && ! (INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX)
280 # if defined O_TTY_INIT && ! (INT_MIN <= O_TTY_INIT && O_TTY_INIT <= INT_MAX)
285 #if !defined O_DIRECT && defined O_DIRECTIO
286 /* Tru64 spells it 'O_DIRECTIO'. */
287 # define O_DIRECT O_DIRECTIO
290 #if !defined O_CLOEXEC && defined O_NOINHERIT
291 /* Mingw spells it 'O_NOINHERIT'. */
292 # define O_CLOEXEC O_NOINHERIT
296 # define O_CLOEXEC 0x40000000 /* Try to not collide with system O_* flags. */
297 # define GNULIB_defined_O_CLOEXEC 1
299 # define GNULIB_defined_O_CLOEXEC 0
307 # define O_DIRECTORY 0
315 # define O_EXEC O_RDONLY /* This is often close enough in older systems. */
318 #ifndef O_IGNORE_CTTY
319 # define O_IGNORE_CTTY 0
331 # define O_NONBLOCK O_NDELAY
334 /* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
335 value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
336 or to 0 as fallback. */
337 #if @GNULIB_NONBLOCKING@
339 # define GNULIB_defined_O_NONBLOCK 0
341 # define GNULIB_defined_O_NONBLOCK 1
343 # define O_NONBLOCK 0x40000000
352 # define O_NOFOLLOW 0
372 # define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
380 # define O_TTY_INIT 0
383 #if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
385 # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
388 /* For systems that distinguish between text and binary I/O.
389 O_BINARY is usually declared in fcntl.h */
390 #if !defined O_BINARY && defined _O_BINARY
391 /* For MSC-compatible compilers. */
392 # define O_BINARY _O_BINARY
393 # define O_TEXT _O_TEXT
396 #if defined __BEOS__ || defined __HAIKU__
397 /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
407 /* Fix up the AT_* macros. */
409 /* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
410 value exceeds INT_MAX, so its use as an int doesn't conform to the
411 C standard, and GCC and Sun C complain in some cases. If the bug
412 is present, undef AT_FDCWD here, so it can be redefined below. */
413 #if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
417 /* Use the same bit pattern as Solaris 9, but with the proper
418 signedness. The bit pattern is important, in case this actually is
419 Solaris with the above workaround. */
421 # define AT_FDCWD (-3041965)
424 /* Use the same values as Solaris 9. This shouldn't matter, but
425 there's no real reason to differ. */
426 #ifndef AT_SYMLINK_NOFOLLOW
427 # define AT_SYMLINK_NOFOLLOW 4096
431 # define AT_REMOVEDIR 1
434 /* Solaris 9 lacks these two, so just pick unique values. */
435 #ifndef AT_SYMLINK_FOLLOW
436 # define AT_SYMLINK_FOLLOW 2
440 # define AT_EACCESS 4
443 /* Ignore this flag if not supported. */
444 #ifndef AT_NO_AUTOMOUNT
445 # define AT_NO_AUTOMOUNT 0
448 #endif /* _@GUARD_PREFIX@_FCNTL_H */
449 #endif /* _@GUARD_PREFIX@_FCNTL_H */