exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / fcntl.in.h
blobeea3b9542a514fcd046bac5878f45435285b2918
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 */
20 #if __GNUC__ >= 3
21 @PRAGMA_SYSTEM_HEADER@
22 #endif
23 @PRAGMA_COLUMNS@
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>
39 #endif
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__)
45 # include <io.h>
46 #endif
48 #else
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>
64 #endif
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__)
71 # include <io.h>
72 #endif
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."
80 #endif
82 #ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
83 # include <unistd.h>
84 #endif
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. */
96 #if @GNULIB_CREAT@
97 # if @REPLACE_CREAT@
98 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
99 # undef creat
100 # define creat rpl_creat
101 # endif
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)
107 # undef creat
108 # define creat _creat
109 # endif
110 _GL_CXXALIAS_MDA (creat, int, (const char *filename, mode_t mode));
111 # else
112 _GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
113 # endif
114 _GL_CXXALIASWARN (creat);
115 #elif defined GNULIB_POSIXCHECK
116 # undef creat
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)
126 # undef creat
127 # define creat _creat
128 # endif
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));
131 # else
132 _GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
133 # endif
134 _GL_CXXALIASWARN (creat);
135 #endif
137 #if @GNULIB_FCNTL@
138 # if @REPLACE_FCNTL@
139 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
140 # undef fcntl
141 # define fcntl rpl_fcntl
142 # endif
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
147 # endif
148 # else
149 # if !@HAVE_FCNTL@
150 _GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
151 # if !GNULIB_defined_fcntl
152 # define GNULIB_defined_fcntl 1
153 # endif
154 # endif
155 _GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
156 # endif
157 _GL_CXXALIASWARN (fcntl);
158 #elif defined GNULIB_POSIXCHECK
159 # undef fcntl
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");
163 # endif
164 #endif
166 #if @GNULIB_OPEN@
167 # if @REPLACE_OPEN@
168 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
169 # undef open
170 # define open rpl_open
171 # endif
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)
177 # undef open
178 # define open _open
179 # endif
180 _GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
181 # else
182 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
183 # endif
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. */
186 # if !defined __hpux
187 _GL_CXXALIASWARN (open);
188 # endif
189 #elif defined GNULIB_POSIXCHECK
190 # undef open
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)
200 # undef open
201 # define open _open
202 # endif
203 _GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
204 # else
205 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
206 # endif
207 # if !defined __hpux
208 _GL_CXXALIASWARN (open);
209 # endif
210 #endif
212 #if @GNULIB_OPENAT@
213 # if @REPLACE_OPENAT@
214 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
215 # undef openat
216 # define openat rpl_openat
217 # endif
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 */ ...));
223 # else
224 # if !@HAVE_OPENAT@
225 _GL_FUNCDECL_SYS (openat, int,
226 (int fd, char const *file, int flags, /* mode_t mode */ ...)
227 _GL_ARG_NONNULL ((2)));
228 # endif
229 _GL_CXXALIAS_SYS (openat, int,
230 (int fd, char const *file, int flags, /* mode_t mode */ ...));
231 # endif
232 _GL_CXXALIASWARN (openat);
233 #elif defined GNULIB_POSIXCHECK
234 # undef openat
235 # if HAVE_RAW_DECL_OPENAT
236 _GL_WARN_ON_USE (openat, "openat is not portable - "
237 "use gnulib module openat for portability");
238 # endif
239 #endif
242 /* Fix up the FD_* macros, only known to be missing on mingw. */
244 #ifndef FD_CLOEXEC
245 # define FD_CLOEXEC 1
246 #endif
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
255 #else
256 # define GNULIB_defined_F_DUPFD_CLOEXEC 0
257 #endif
259 #ifndef F_DUPFD
260 # define F_DUPFD 1
261 #endif
263 #ifndef F_GETFD
264 # define F_GETFD 2
265 #endif
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. */
272 #ifdef _AIX
273 # include <limits.h>
274 # if defined O_CLOEXEC && ! (INT_MIN <= O_CLOEXEC && O_CLOEXEC <= INT_MAX)
275 # undef O_CLOEXEC
276 # endif
277 # if defined O_NOFOLLOW && ! (INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX)
278 # undef O_NOFOLLOW
279 # endif
280 # if defined O_TTY_INIT && ! (INT_MIN <= O_TTY_INIT && O_TTY_INIT <= INT_MAX)
281 # undef O_TTY_INIT
282 # endif
283 #endif
285 #if !defined O_DIRECT && defined O_DIRECTIO
286 /* Tru64 spells it 'O_DIRECTIO'. */
287 # define O_DIRECT O_DIRECTIO
288 #endif
290 #if !defined O_CLOEXEC && defined O_NOINHERIT
291 /* Mingw spells it 'O_NOINHERIT'. */
292 # define O_CLOEXEC O_NOINHERIT
293 #endif
295 #ifndef O_CLOEXEC
296 # define O_CLOEXEC 0x40000000 /* Try to not collide with system O_* flags. */
297 # define GNULIB_defined_O_CLOEXEC 1
298 #else
299 # define GNULIB_defined_O_CLOEXEC 0
300 #endif
302 #ifndef O_DIRECT
303 # define O_DIRECT 0
304 #endif
306 #ifndef O_DIRECTORY
307 # define O_DIRECTORY 0
308 #endif
310 #ifndef O_DSYNC
311 # define O_DSYNC 0
312 #endif
314 #ifndef O_EXEC
315 # define O_EXEC O_RDONLY /* This is often close enough in older systems. */
316 #endif
318 #ifndef O_IGNORE_CTTY
319 # define O_IGNORE_CTTY 0
320 #endif
322 #ifndef O_NDELAY
323 # define O_NDELAY 0
324 #endif
326 #ifndef O_NOATIME
327 # define O_NOATIME 0
328 #endif
330 #ifndef O_NONBLOCK
331 # define O_NONBLOCK O_NDELAY
332 #endif
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@
338 # if O_NONBLOCK
339 # define GNULIB_defined_O_NONBLOCK 0
340 # else
341 # define GNULIB_defined_O_NONBLOCK 1
342 # undef O_NONBLOCK
343 # define O_NONBLOCK 0x40000000
344 # endif
345 #endif
347 #ifndef O_NOCTTY
348 # define O_NOCTTY 0
349 #endif
351 #ifndef O_NOFOLLOW
352 # define O_NOFOLLOW 0
353 #endif
355 #ifndef O_NOLINK
356 # define O_NOLINK 0
357 #endif
359 #ifndef O_NOLINKS
360 # define O_NOLINKS 0
361 #endif
363 #ifndef O_NOTRANS
364 # define O_NOTRANS 0
365 #endif
367 #ifndef O_RSYNC
368 # define O_RSYNC 0
369 #endif
371 #ifndef O_SEARCH
372 # define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
373 #endif
375 #ifndef O_SYNC
376 # define O_SYNC 0
377 #endif
379 #ifndef O_TTY_INIT
380 # define O_TTY_INIT 0
381 #endif
383 #if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
384 # undef O_ACCMODE
385 # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
386 #endif
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
394 #endif
396 #if defined __BEOS__ || defined __HAIKU__
397 /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
398 # undef O_BINARY
399 # undef O_TEXT
400 #endif
402 #ifndef O_BINARY
403 # define O_BINARY 0
404 # define O_TEXT 0
405 #endif
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
414 # undef AT_FDCWD
415 #endif
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. */
420 #ifndef AT_FDCWD
421 # define AT_FDCWD (-3041965)
422 #endif
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
428 #endif
430 #ifndef AT_REMOVEDIR
431 # define AT_REMOVEDIR 1
432 #endif
434 /* Solaris 9 lacks these two, so just pick unique values. */
435 #ifndef AT_SYMLINK_FOLLOW
436 # define AT_SYMLINK_FOLLOW 2
437 #endif
439 #ifndef AT_EACCESS
440 # define AT_EACCESS 4
441 #endif
443 /* Ignore this flag if not supported. */
444 #ifndef AT_NO_AUTOMOUNT
445 # define AT_NO_AUTOMOUNT 0
446 #endif
448 #endif /* _@GUARD_PREFIX@_FCNTL_H */
449 #endif /* _@GUARD_PREFIX@_FCNTL_H */
450 #endif