execute, spawn-pipe: Make multithread-safe on native Windows.
[gnulib.git] / lib / fcntl.in.h
blob6f16bc6692150a23a36696b43012e6970b80c4fb
1 /* Like <fcntl.h>, but with non-working flags defined to 0.
3 Copyright (C) 2006-2020 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program 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 General Public License for more details.
15 You should have received a copy of the GNU 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 #ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
78 # include <unistd.h>
79 #endif
82 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
84 /* The definition of _GL_ARG_NONNULL is copied here. */
86 /* The definition of _GL_WARN_ON_USE is copied here. */
89 /* Declare overridden functions. */
91 #if @GNULIB_CREAT@
92 # if @REPLACE_CREAT@
93 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
94 # undef creat
95 # define creat rpl_creat
96 # endif
97 _GL_FUNCDECL_RPL (creat, int, (const char *filename, mode_t mode)
98 _GL_ARG_NONNULL ((1)));
99 _GL_CXXALIAS_RPL (creat, int, (const char *filename, mode_t mode));
100 # elif defined _WIN32 && !defined __CYGWIN__
101 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
102 # undef creat
103 # define creat _creat
104 # endif
105 _GL_CXXALIAS_MDA (creat, int, (const char *filename, mode_t mode));
106 # else
107 _GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
108 # endif
109 _GL_CXXALIASWARN (creat);
110 #elif defined GNULIB_POSIXCHECK
111 # undef creat
112 /* Assume creat is always declared. */
113 _GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - "
114 "use gnulib module creat for portability");
115 #elif defined _WIN32 && !defined __CYGWIN__
116 # undef creat
117 # define creat _creat
118 #endif
120 #if @GNULIB_FCNTL@
121 # if @REPLACE_FCNTL@
122 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
123 # undef fcntl
124 # define fcntl rpl_fcntl
125 # endif
126 _GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
127 _GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
128 # if !GNULIB_defined_rpl_fcntl
129 # define GNULIB_defined_rpl_fcntl 1
130 # endif
131 # else
132 # if !@HAVE_FCNTL@
133 _GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
134 # if !GNULIB_defined_fcntl
135 # define GNULIB_defined_fcntl 1
136 # endif
137 # endif
138 _GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
139 # endif
140 _GL_CXXALIASWARN (fcntl);
141 #elif defined GNULIB_POSIXCHECK
142 # undef fcntl
143 # if HAVE_RAW_DECL_FCNTL
144 _GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
145 "use gnulib module fcntl for portability");
146 # endif
147 #endif
149 #if @GNULIB_OPEN@
150 # if @REPLACE_OPEN@
151 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
152 # undef open
153 # define open rpl_open
154 # endif
155 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
156 _GL_ARG_NONNULL ((1)));
157 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
158 # elif defined _WIN32 && !defined __CYGWIN__
159 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
160 # undef open
161 # define open _open
162 # endif
163 _GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
164 # else
165 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
166 # endif
167 /* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
168 default argument. _GL_CXXALIASWARN does not work in this case. */
169 # if !defined __hpux
170 _GL_CXXALIASWARN (open);
171 # endif
172 #elif defined GNULIB_POSIXCHECK
173 # undef open
174 /* Assume open is always declared. */
175 _GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
176 "use gnulib module open for portability");
177 #elif defined _WIN32 && !defined __CYGWIN__
178 # undef open
179 # define open _open
180 #endif
182 #if @GNULIB_OPENAT@
183 # if @REPLACE_OPENAT@
184 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
185 # undef openat
186 # define openat rpl_openat
187 # endif
188 _GL_FUNCDECL_RPL (openat, int,
189 (int fd, char const *file, int flags, /* mode_t mode */ ...)
190 _GL_ARG_NONNULL ((2)));
191 _GL_CXXALIAS_RPL (openat, int,
192 (int fd, char const *file, int flags, /* mode_t mode */ ...));
193 # else
194 # if !@HAVE_OPENAT@
195 _GL_FUNCDECL_SYS (openat, int,
196 (int fd, char const *file, int flags, /* mode_t mode */ ...)
197 _GL_ARG_NONNULL ((2)));
198 # endif
199 _GL_CXXALIAS_SYS (openat, int,
200 (int fd, char const *file, int flags, /* mode_t mode */ ...));
201 # endif
202 _GL_CXXALIASWARN (openat);
203 #elif defined GNULIB_POSIXCHECK
204 # undef openat
205 # if HAVE_RAW_DECL_OPENAT
206 _GL_WARN_ON_USE (openat, "openat is not portable - "
207 "use gnulib module openat for portability");
208 # endif
209 #endif
212 /* Fix up the FD_* macros, only known to be missing on mingw. */
214 #ifndef FD_CLOEXEC
215 # define FD_CLOEXEC 1
216 #endif
218 /* Fix up the supported F_* macros. Intentionally leave other F_*
219 macros undefined. Only known to be missing on mingw. */
221 #ifndef F_DUPFD_CLOEXEC
222 # define F_DUPFD_CLOEXEC 0x40000000
223 /* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
224 # define GNULIB_defined_F_DUPFD_CLOEXEC 1
225 #else
226 # define GNULIB_defined_F_DUPFD_CLOEXEC 0
227 #endif
229 #ifndef F_DUPFD
230 # define F_DUPFD 1
231 #endif
233 #ifndef F_GETFD
234 # define F_GETFD 2
235 #endif
237 /* Fix up the O_* macros. */
239 /* AIX 7.1 with XL C 12.1 defines O_CLOEXEC, O_NOFOLLOW, and O_TTY_INIT
240 to values outside 'int' range, so omit these misdefinitions.
241 But avoid namespace pollution on non-AIX systems. */
242 #ifdef _AIX
243 # include <limits.h>
244 # if defined O_CLOEXEC && ! (INT_MIN <= O_CLOEXEC && O_CLOEXEC <= INT_MAX)
245 # undef O_CLOEXEC
246 # endif
247 # if defined O_NOFOLLOW && ! (INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX)
248 # undef O_NOFOLLOW
249 # endif
250 # if defined O_TTY_INIT && ! (INT_MIN <= O_TTY_INIT && O_TTY_INIT <= INT_MAX)
251 # undef O_TTY_INIT
252 # endif
253 #endif
255 #if !defined O_DIRECT && defined O_DIRECTIO
256 /* Tru64 spells it 'O_DIRECTIO'. */
257 # define O_DIRECT O_DIRECTIO
258 #endif
260 #if !defined O_CLOEXEC && defined O_NOINHERIT
261 /* Mingw spells it 'O_NOINHERIT'. */
262 # define O_CLOEXEC O_NOINHERIT
263 #endif
265 #ifndef O_CLOEXEC
266 # define O_CLOEXEC 0x40000000 /* Try to not collide with system O_* flags. */
267 # define GNULIB_defined_O_CLOEXEC 1
268 #else
269 # define GNULIB_defined_O_CLOEXEC 0
270 #endif
272 #ifndef O_DIRECT
273 # define O_DIRECT 0
274 #endif
276 #ifndef O_DIRECTORY
277 # define O_DIRECTORY 0
278 #endif
280 #ifndef O_DSYNC
281 # define O_DSYNC 0
282 #endif
284 #ifndef O_EXEC
285 # define O_EXEC O_RDONLY /* This is often close enough in older systems. */
286 #endif
288 #ifndef O_IGNORE_CTTY
289 # define O_IGNORE_CTTY 0
290 #endif
292 #ifndef O_NDELAY
293 # define O_NDELAY 0
294 #endif
296 #ifndef O_NOATIME
297 # define O_NOATIME 0
298 #endif
300 #ifndef O_NONBLOCK
301 # define O_NONBLOCK O_NDELAY
302 #endif
304 /* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
305 value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
306 or to 0 as fallback. */
307 #if @GNULIB_NONBLOCKING@
308 # if O_NONBLOCK
309 # define GNULIB_defined_O_NONBLOCK 0
310 # else
311 # define GNULIB_defined_O_NONBLOCK 1
312 # undef O_NONBLOCK
313 # define O_NONBLOCK 0x40000000
314 # endif
315 #endif
317 #ifndef O_NOCTTY
318 # define O_NOCTTY 0
319 #endif
321 #ifndef O_NOFOLLOW
322 # define O_NOFOLLOW 0
323 #endif
325 #ifndef O_NOLINK
326 # define O_NOLINK 0
327 #endif
329 #ifndef O_NOLINKS
330 # define O_NOLINKS 0
331 #endif
333 #ifndef O_NOTRANS
334 # define O_NOTRANS 0
335 #endif
337 #ifndef O_RSYNC
338 # define O_RSYNC 0
339 #endif
341 #ifndef O_SEARCH
342 # define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
343 #endif
345 #ifndef O_SYNC
346 # define O_SYNC 0
347 #endif
349 #ifndef O_TTY_INIT
350 # define O_TTY_INIT 0
351 #endif
353 #if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
354 # undef O_ACCMODE
355 # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
356 #endif
358 /* For systems that distinguish between text and binary I/O.
359 O_BINARY is usually declared in fcntl.h */
360 #if !defined O_BINARY && defined _O_BINARY
361 /* For MSC-compatible compilers. */
362 # define O_BINARY _O_BINARY
363 # define O_TEXT _O_TEXT
364 #endif
366 #if defined __BEOS__ || defined __HAIKU__
367 /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
368 # undef O_BINARY
369 # undef O_TEXT
370 #endif
372 #ifndef O_BINARY
373 # define O_BINARY 0
374 # define O_TEXT 0
375 #endif
377 /* Fix up the AT_* macros. */
379 /* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
380 value exceeds INT_MAX, so its use as an int doesn't conform to the
381 C standard, and GCC and Sun C complain in some cases. If the bug
382 is present, undef AT_FDCWD here, so it can be redefined below. */
383 #if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
384 # undef AT_FDCWD
385 #endif
387 /* Use the same bit pattern as Solaris 9, but with the proper
388 signedness. The bit pattern is important, in case this actually is
389 Solaris with the above workaround. */
390 #ifndef AT_FDCWD
391 # define AT_FDCWD (-3041965)
392 #endif
394 /* Use the same values as Solaris 9. This shouldn't matter, but
395 there's no real reason to differ. */
396 #ifndef AT_SYMLINK_NOFOLLOW
397 # define AT_SYMLINK_NOFOLLOW 4096
398 #endif
400 #ifndef AT_REMOVEDIR
401 # define AT_REMOVEDIR 1
402 #endif
404 /* Solaris 9 lacks these two, so just pick unique values. */
405 #ifndef AT_SYMLINK_FOLLOW
406 # define AT_SYMLINK_FOLLOW 2
407 #endif
409 #ifndef AT_EACCESS
410 # define AT_EACCESS 4
411 #endif
414 #endif /* _@GUARD_PREFIX@_FCNTL_H */
415 #endif /* _@GUARD_PREFIX@_FCNTL_H */
416 #endif