fcntl.in.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /* Like <fcntl.h>, but with non-working flags defined to 0.
  2. Copyright (C) 2006-2021 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. /* written by Paul Eggert */
  14. #if __GNUC__ >= 3
  15. @PRAGMA_SYSTEM_HEADER@
  16. #endif
  17. @PRAGMA_COLUMNS@
  18. #if defined __need_system_fcntl_h
  19. /* Special invocation convention. */
  20. /* Needed before <sys/stat.h>.
  21. May also define off_t to a 64-bit type on native Windows. */
  22. #include <sys/types.h>
  23. /* On some systems other than glibc, <sys/stat.h> is a prerequisite of
  24. <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
  25. But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
  26. extern "C" { ... } block, which leads to errors in C++ mode with the
  27. overridden <sys/stat.h> from gnulib. These errors are known to be gone
  28. with g++ version >= 4.3. */
  29. #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
  30. # include <sys/stat.h>
  31. #endif
  32. #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
  33. /* Native Windows platforms declare open(), creat() in <io.h>. */
  34. #if (@GNULIB_CREAT@ || @GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
  35. && (defined _WIN32 && ! defined __CYGWIN__)
  36. # include <io.h>
  37. #endif
  38. #else
  39. /* Normal invocation convention. */
  40. #ifndef _@GUARD_PREFIX@_FCNTL_H
  41. /* Needed before <sys/stat.h>.
  42. May also define off_t to a 64-bit type on native Windows. */
  43. #include <sys/types.h>
  44. /* On some systems other than glibc, <sys/stat.h> is a prerequisite of
  45. <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
  46. But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
  47. extern "C" { ... } block, which leads to errors in C++ mode with the
  48. overridden <sys/stat.h> from gnulib. These errors are known to be gone
  49. with g++ version >= 4.3. */
  50. #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && (defined __ICC || !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))))
  51. # include <sys/stat.h>
  52. #endif
  53. /* The include_next requires a split double-inclusion guard. */
  54. #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
  55. /* Native Windows platforms declare open(), creat() in <io.h>. */
  56. #if (@GNULIB_CREAT@ || @GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
  57. && (defined _WIN32 && ! defined __CYGWIN__)
  58. # include <io.h>
  59. #endif
  60. #ifndef _@GUARD_PREFIX@_FCNTL_H
  61. #define _@GUARD_PREFIX@_FCNTL_H
  62. #ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
  63. # include <unistd.h>
  64. #endif
  65. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  66. /* The definition of _GL_ARG_NONNULL is copied here. */
  67. /* The definition of _GL_WARN_ON_USE is copied here. */
  68. /* Declare overridden functions. */
  69. #if @GNULIB_CREAT@
  70. # if @REPLACE_CREAT@
  71. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  72. # undef creat
  73. # define creat rpl_creat
  74. # endif
  75. _GL_FUNCDECL_RPL (creat, int, (const char *filename, mode_t mode)
  76. _GL_ARG_NONNULL ((1)));
  77. _GL_CXXALIAS_RPL (creat, int, (const char *filename, mode_t mode));
  78. # elif defined _WIN32 && !defined __CYGWIN__
  79. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  80. # undef creat
  81. # define creat _creat
  82. # endif
  83. _GL_CXXALIAS_MDA (creat, int, (const char *filename, mode_t mode));
  84. # else
  85. _GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
  86. # endif
  87. _GL_CXXALIASWARN (creat);
  88. #elif defined GNULIB_POSIXCHECK
  89. # undef creat
  90. /* Assume creat is always declared. */
  91. _GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - "
  92. "use gnulib module creat for portability");
  93. #elif @GNULIB_MDA_CREAT@
  94. /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
  95. required. In C++ with GNULIB_NAMESPACE, avoid differences between
  96. platforms by defining GNULIB_NAMESPACE::creat always. */
  97. # if defined _WIN32 && !defined __CYGWIN__
  98. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  99. # undef creat
  100. # define creat _creat
  101. # endif
  102. /* Need to cast, because in mingw the last argument is 'int mode'. */
  103. _GL_CXXALIAS_MDA_CAST (creat, int, (const char *filename, mode_t mode));
  104. # else
  105. _GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
  106. # endif
  107. _GL_CXXALIASWARN (creat);
  108. #endif
  109. #if @GNULIB_FCNTL@
  110. # if @REPLACE_FCNTL@
  111. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  112. # undef fcntl
  113. # define fcntl rpl_fcntl
  114. # endif
  115. _GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
  116. _GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
  117. # if !GNULIB_defined_rpl_fcntl
  118. # define GNULIB_defined_rpl_fcntl 1
  119. # endif
  120. # else
  121. # if !@HAVE_FCNTL@
  122. _GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
  123. # if !GNULIB_defined_fcntl
  124. # define GNULIB_defined_fcntl 1
  125. # endif
  126. # endif
  127. _GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
  128. # endif
  129. _GL_CXXALIASWARN (fcntl);
  130. #elif defined GNULIB_POSIXCHECK
  131. # undef fcntl
  132. # if HAVE_RAW_DECL_FCNTL
  133. _GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
  134. "use gnulib module fcntl for portability");
  135. # endif
  136. #endif
  137. #if @GNULIB_OPEN@
  138. # if @REPLACE_OPEN@
  139. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  140. # undef open
  141. # define open rpl_open
  142. # endif
  143. _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
  144. _GL_ARG_NONNULL ((1)));
  145. _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
  146. # elif defined _WIN32 && !defined __CYGWIN__
  147. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  148. # undef open
  149. # define open _open
  150. # endif
  151. _GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
  152. # else
  153. _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
  154. # endif
  155. /* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
  156. default argument. _GL_CXXALIASWARN does not work in this case. */
  157. # if !defined __hpux
  158. _GL_CXXALIASWARN (open);
  159. # endif
  160. #elif defined GNULIB_POSIXCHECK
  161. # undef open
  162. /* Assume open is always declared. */
  163. _GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
  164. "use gnulib module open for portability");
  165. #elif @GNULIB_MDA_OPEN@
  166. /* On native Windows, map 'open' to '_open', so that -loldnames is not
  167. required. In C++ with GNULIB_NAMESPACE, avoid differences between
  168. platforms by defining GNULIB_NAMESPACE::open always. */
  169. # if defined _WIN32 && !defined __CYGWIN__
  170. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  171. # undef open
  172. # define open _open
  173. # endif
  174. _GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
  175. # else
  176. _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
  177. # endif
  178. # if !defined __hpux
  179. _GL_CXXALIASWARN (open);
  180. # endif
  181. #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
  210. /* Fix up the FD_* macros, only known to be missing on mingw. */
  211. #ifndef FD_CLOEXEC
  212. # define FD_CLOEXEC 1
  213. #endif
  214. /* Fix up the supported F_* macros. Intentionally leave other F_*
  215. macros undefined. Only known to be missing on mingw. */
  216. #ifndef F_DUPFD_CLOEXEC
  217. # define F_DUPFD_CLOEXEC 0x40000000
  218. /* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
  219. # define GNULIB_defined_F_DUPFD_CLOEXEC 1
  220. #else
  221. # define GNULIB_defined_F_DUPFD_CLOEXEC 0
  222. #endif
  223. #ifndef F_DUPFD
  224. # define F_DUPFD 1
  225. #endif
  226. #ifndef F_GETFD
  227. # define F_GETFD 2
  228. #endif
  229. /* Fix up the O_* macros. */
  230. /* AIX 7.1 with XL C 12.1 defines O_CLOEXEC, O_NOFOLLOW, and O_TTY_INIT
  231. to values outside 'int' range, so omit these misdefinitions.
  232. But avoid namespace pollution on non-AIX systems. */
  233. #ifdef _AIX
  234. # include <limits.h>
  235. # if defined O_CLOEXEC && ! (INT_MIN <= O_CLOEXEC && O_CLOEXEC <= INT_MAX)
  236. # undef O_CLOEXEC
  237. # endif
  238. # if defined O_NOFOLLOW && ! (INT_MIN <= O_NOFOLLOW && O_NOFOLLOW <= INT_MAX)
  239. # undef O_NOFOLLOW
  240. # endif
  241. # if defined O_TTY_INIT && ! (INT_MIN <= O_TTY_INIT && O_TTY_INIT <= INT_MAX)
  242. # undef O_TTY_INIT
  243. # endif
  244. #endif
  245. #if !defined O_DIRECT && defined O_DIRECTIO
  246. /* Tru64 spells it 'O_DIRECTIO'. */
  247. # define O_DIRECT O_DIRECTIO
  248. #endif
  249. #if !defined O_CLOEXEC && defined O_NOINHERIT
  250. /* Mingw spells it 'O_NOINHERIT'. */
  251. # define O_CLOEXEC O_NOINHERIT
  252. #endif
  253. #ifndef O_CLOEXEC
  254. # define O_CLOEXEC 0x40000000 /* Try to not collide with system O_* flags. */
  255. # define GNULIB_defined_O_CLOEXEC 1
  256. #else
  257. # define GNULIB_defined_O_CLOEXEC 0
  258. #endif
  259. #ifndef O_DIRECT
  260. # define O_DIRECT 0
  261. #endif
  262. #ifndef O_DIRECTORY
  263. # define O_DIRECTORY 0
  264. #endif
  265. #ifndef O_DSYNC
  266. # define O_DSYNC 0
  267. #endif
  268. #ifndef O_EXEC
  269. # define O_EXEC O_RDONLY /* This is often close enough in older systems. */
  270. #endif
  271. #ifndef O_IGNORE_CTTY
  272. # define O_IGNORE_CTTY 0
  273. #endif
  274. #ifndef O_NDELAY
  275. # define O_NDELAY 0
  276. #endif
  277. #ifndef O_NOATIME
  278. # define O_NOATIME 0
  279. #endif
  280. #ifndef O_NONBLOCK
  281. # define O_NONBLOCK O_NDELAY
  282. #endif
  283. /* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
  284. value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
  285. or to 0 as fallback. */
  286. #if @GNULIB_NONBLOCKING@
  287. # if O_NONBLOCK
  288. # define GNULIB_defined_O_NONBLOCK 0
  289. # else
  290. # define GNULIB_defined_O_NONBLOCK 1
  291. # undef O_NONBLOCK
  292. # define O_NONBLOCK 0x40000000
  293. # endif
  294. #endif
  295. #ifndef O_NOCTTY
  296. # define O_NOCTTY 0
  297. #endif
  298. #ifndef O_NOFOLLOW
  299. # define O_NOFOLLOW 0
  300. #endif
  301. #ifndef O_NOLINK
  302. # define O_NOLINK 0
  303. #endif
  304. #ifndef O_NOLINKS
  305. # define O_NOLINKS 0
  306. #endif
  307. #ifndef O_NOTRANS
  308. # define O_NOTRANS 0
  309. #endif
  310. #ifndef O_RSYNC
  311. # define O_RSYNC 0
  312. #endif
  313. #ifndef O_SEARCH
  314. # define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
  315. #endif
  316. #ifndef O_SYNC
  317. # define O_SYNC 0
  318. #endif
  319. #ifndef O_TTY_INIT
  320. # define O_TTY_INIT 0
  321. #endif
  322. #if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
  323. # undef O_ACCMODE
  324. # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
  325. #endif
  326. /* For systems that distinguish between text and binary I/O.
  327. O_BINARY is usually declared in fcntl.h */
  328. #if !defined O_BINARY && defined _O_BINARY
  329. /* For MSC-compatible compilers. */
  330. # define O_BINARY _O_BINARY
  331. # define O_TEXT _O_TEXT
  332. #endif
  333. #if defined __BEOS__ || defined __HAIKU__
  334. /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
  335. # undef O_BINARY
  336. # undef O_TEXT
  337. #endif
  338. #ifndef O_BINARY
  339. # define O_BINARY 0
  340. # define O_TEXT 0
  341. #endif
  342. /* Fix up the AT_* macros. */
  343. /* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
  344. value exceeds INT_MAX, so its use as an int doesn't conform to the
  345. C standard, and GCC and Sun C complain in some cases. If the bug
  346. is present, undef AT_FDCWD here, so it can be redefined below. */
  347. #if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
  348. # undef AT_FDCWD
  349. #endif
  350. /* Use the same bit pattern as Solaris 9, but with the proper
  351. signedness. The bit pattern is important, in case this actually is
  352. Solaris with the above workaround. */
  353. #ifndef AT_FDCWD
  354. # define AT_FDCWD (-3041965)
  355. #endif
  356. /* Use the same values as Solaris 9. This shouldn't matter, but
  357. there's no real reason to differ. */
  358. #ifndef AT_SYMLINK_NOFOLLOW
  359. # define AT_SYMLINK_NOFOLLOW 4096
  360. #endif
  361. #ifndef AT_REMOVEDIR
  362. # define AT_REMOVEDIR 1
  363. #endif
  364. /* Solaris 9 lacks these two, so just pick unique values. */
  365. #ifndef AT_SYMLINK_FOLLOW
  366. # define AT_SYMLINK_FOLLOW 2
  367. #endif
  368. #ifndef AT_EACCESS
  369. # define AT_EACCESS 4
  370. #endif
  371. #endif /* _@GUARD_PREFIX@_FCNTL_H */
  372. #endif /* _@GUARD_PREFIX@_FCNTL_H */
  373. #endif