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 Also defines off64_t on macOS, NetBSD, OpenBSD, MSVC, Cygwin, Haiku. */
56 #include <sys/types.h>
57 /* On some systems other than glibc, <sys/stat.h> is a prerequisite of
58 <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
59 But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
60 extern "C" { ... } block, which leads to errors in C++ mode with the
61 overridden <sys/stat.h> from gnulib. These errors are known to be gone
62 with g++ version >= 4.3. */
63 #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
64 # include <sys/stat.h>
66 /* The include_next requires a split double-inclusion guard. */
67 #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
69 /* Native Windows platforms declare open(), creat() in <io.h>. */
70 #if (@GNULIB_CREAT@ || @GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
71 && (defined _WIN32 && ! defined __CYGWIN__)
75 #ifndef _@GUARD_PREFIX@_FCNTL_H
76 #define _@GUARD_PREFIX@_FCNTL_H
78 /* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
79 #if !_GL_CONFIG_H_INCLUDED
80 #error "Please include config.h first."
83 #ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
88 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
90 /* The definition of _GL_ARG_NONNULL is copied here. */
92 /* The definition of _GL_WARN_ON_USE is copied here. */
95 /* Declare overridden functions. */
99 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
101 # define creat rpl_creat
103 _GL_FUNCDECL_RPL (creat
, int, (const char *filename
, mode_t mode
),
104 _GL_ARG_NONNULL ((1)));
105 _GL_CXXALIAS_RPL (creat
, int, (const char *filename
, mode_t mode
));
106 # elif defined _WIN32 && !defined __CYGWIN__
107 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
109 # define creat _creat
111 _GL_CXXALIAS_MDA (creat
, int, (const char *filename
, mode_t mode
));
113 _GL_CXXALIAS_SYS (creat
, int, (const char *filename
, mode_t mode
));
115 _GL_CXXALIASWARN (creat
);
116 #elif defined GNULIB_POSIXCHECK
118 /* Assume creat is always declared. */
119 _GL_WARN_ON_USE (creat
, "creat is not always POSIX compliant - "
120 "use gnulib module creat for portability");
121 #elif @GNULIB_MDA_CREAT@
122 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
123 required. In C++ with GNULIB_NAMESPACE, avoid differences between
124 platforms by defining GNULIB_NAMESPACE::creat always. */
125 # if defined _WIN32 && !defined __CYGWIN__
126 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
128 # define creat _creat
130 /* Need to cast, because in mingw the last argument is 'int mode'. */
131 _GL_CXXALIAS_MDA_CAST (creat
, int, (const char *filename
, mode_t mode
));
133 _GL_CXXALIAS_SYS (creat
, int, (const char *filename
, mode_t mode
));
135 _GL_CXXALIASWARN (creat
);
140 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
142 # define fcntl rpl_fcntl
144 _GL_FUNCDECL_RPL (fcntl
, int, (int fd
, int action
, ...), );
145 _GL_CXXALIAS_RPL (fcntl
, int, (int fd
, int action
, ...));
146 # if !GNULIB_defined_rpl_fcntl
147 # define GNULIB_defined_rpl_fcntl 1
151 _GL_FUNCDECL_SYS (fcntl
, int, (int fd
, int action
, ...), );
152 # if !GNULIB_defined_fcntl
153 # define GNULIB_defined_fcntl 1
156 _GL_CXXALIAS_SYS (fcntl
, int, (int fd
, int action
, ...));
158 _GL_CXXALIASWARN (fcntl
);
159 #elif defined GNULIB_POSIXCHECK
161 # if HAVE_RAW_DECL_FCNTL
162 _GL_WARN_ON_USE (fcntl
, "fcntl is not always POSIX compliant - "
163 "use gnulib module fcntl for portability");
169 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
171 # define open rpl_open
173 _GL_FUNCDECL_RPL (open
, int, (const char *filename
, int flags
, ...),
174 _GL_ARG_NONNULL ((1)));
175 _GL_CXXALIAS_RPL (open
, int, (const char *filename
, int flags
, ...));
176 # elif defined _WIN32 && !defined __CYGWIN__
177 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
181 _GL_CXXALIAS_MDA (open
, int, (const char *filename
, int flags
, ...));
183 _GL_CXXALIAS_SYS (open
, int, (const char *filename
, int flags
, ...));
185 /* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
186 default argument. _GL_CXXALIASWARN does not work in this case. */
188 _GL_CXXALIASWARN (open
);
190 #elif defined GNULIB_POSIXCHECK
192 /* Assume open is always declared. */
193 _GL_WARN_ON_USE (open
, "open is not always POSIX compliant - "
194 "use gnulib module open for portability");
195 #elif @GNULIB_MDA_OPEN@
196 /* On native Windows, map 'open' to '_open', so that -loldnames is not
197 required. In C++ with GNULIB_NAMESPACE, avoid differences between
198 platforms by defining GNULIB_NAMESPACE::open always. */
199 # if defined _WIN32 && !defined __CYGWIN__
200 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
204 _GL_CXXALIAS_MDA (open
, int, (const char *filename
, int flags
, ...));
206 _GL_CXXALIAS_SYS (open
, int, (const char *filename
, int flags
, ...));
209 _GL_CXXALIASWARN (open
);
214 # if @REPLACE_OPENAT@
215 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
217 # define openat rpl_openat
219 _GL_FUNCDECL_RPL (openat
, int,
220 (int fd
, char const *file
, int flags
, /* mode_t mode */ ...),
221 _GL_ARG_NONNULL ((2)));
222 _GL_CXXALIAS_RPL (openat
, int,
223 (int fd
, char const *file
, int flags
, /* mode_t mode */ ...));
226 _GL_FUNCDECL_SYS (openat
, int,
227 (int fd
, char const *file
, int flags
, /* mode_t mode */ ...),
228 _GL_ARG_NONNULL ((2)));
230 _GL_CXXALIAS_SYS (openat
, int,
231 (int fd
, char const *file
, int flags
, /* mode_t mode */ ...));
233 _GL_CXXALIASWARN (openat
);
234 #elif defined GNULIB_POSIXCHECK
236 # if HAVE_RAW_DECL_OPENAT
237 _GL_WARN_ON_USE (openat
, "openat is not portable - "
238 "use gnulib module openat for portability");
243 /* Fix up the FD_* macros, only known to be missing on mingw. */
246 # define FD_CLOEXEC 1
249 /* Fix up the supported F_* macros. Intentionally leave other F_*
250 macros undefined. Only known to be missing on mingw. */
252 #ifndef F_DUPFD_CLOEXEC
253 # define F_DUPFD_CLOEXEC 0x40000000
254 /* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
255 # define GNULIB_defined_F_DUPFD_CLOEXEC 1
257 # define GNULIB_defined_F_DUPFD_CLOEXEC 0
268 /* Fix up the O_* macros. */
270 /* AIX 7.1 with XL C 12.1 defines O_CLOEXEC, O_NOFOLLOW, and O_TTY_INIT
271 to values outside 'int' range, so omit these misdefinitions.
272 But avoid namespace pollution on non-AIX systems. */
275 # if defined O_CLOEXEC && ! (INT_MIN <= O_CLOEXEC && O_CLOEXEC <= INT_MAX)
278 # if defined O_NOFOLLOW && ! (INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX)
281 # if defined O_TTY_INIT && ! (INT_MIN <= O_TTY_INIT && O_TTY_INIT <= INT_MAX)
286 #if !defined O_DIRECT && defined O_DIRECTIO
287 /* Tru64 spells it 'O_DIRECTIO'. */
288 # define O_DIRECT O_DIRECTIO
291 #if !defined O_CLOEXEC && defined O_NOINHERIT
292 /* Mingw spells it 'O_NOINHERIT'. */
293 # define O_CLOEXEC O_NOINHERIT
297 # define O_CLOEXEC 0x40000000 /* Try to not collide with system O_* flags. */
298 # define GNULIB_defined_O_CLOEXEC 1
300 # define GNULIB_defined_O_CLOEXEC 0
308 # define O_DIRECTORY 0
316 # define O_EXEC O_RDONLY /* This is often close enough in older systems. */
319 #ifndef O_IGNORE_CTTY
320 # define O_IGNORE_CTTY 0
332 # define O_NONBLOCK O_NDELAY
335 /* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
336 value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
337 or to 0 as fallback. */
338 #if @GNULIB_NONBLOCKING@
340 # define GNULIB_defined_O_NONBLOCK 0
342 # define GNULIB_defined_O_NONBLOCK 1
344 # define O_NONBLOCK 0x40000000
353 # define O_NOFOLLOW 0
373 # define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
381 # define O_TTY_INIT 0
384 #if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
386 # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
389 /* For systems that distinguish between text and binary I/O.
390 O_BINARY is usually declared in fcntl.h */
391 #if !defined O_BINARY && defined _O_BINARY
392 /* For MSC-compatible compilers. */
393 # define O_BINARY _O_BINARY
394 # define O_TEXT _O_TEXT
397 #if defined __BEOS__ || defined __HAIKU__
398 /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
408 /* Fix up the AT_* macros. */
410 /* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
411 value exceeds INT_MAX, so its use as an int doesn't conform to the
412 C standard, and GCC and Sun C complain in some cases. If the bug
413 is present, undef AT_FDCWD here, so it can be redefined below. */
414 #if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
418 /* Use the same bit pattern as Solaris 9, but with the proper
419 signedness. The bit pattern is important, in case this actually is
420 Solaris with the above workaround. */
422 # define AT_FDCWD (-3041965)
425 /* Use the same values as Solaris 9. This shouldn't matter, but
426 there's no real reason to differ. */
427 #ifndef AT_SYMLINK_NOFOLLOW
428 # define AT_SYMLINK_NOFOLLOW 4096
432 # define AT_REMOVEDIR 1
435 /* Solaris 9 lacks these two, so just pick unique values. */
436 #ifndef AT_SYMLINK_FOLLOW
437 # define AT_SYMLINK_FOLLOW 2
441 # define AT_EACCESS 4
444 /* Ignore this flag if not supported. */
445 #ifndef AT_NO_AUTOMOUNT
446 # define AT_NO_AUTOMOUNT 0
449 #endif /* _@GUARD_PREFIX@_FCNTL_H */
450 #endif /* _@GUARD_PREFIX@_FCNTL_H */