fcntl.in.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /* Like <fcntl.h>, but with non-working flags defined to 0.
  2. Copyright (C) 2006-2014 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 Lesser 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://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 && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
  30. # include <sys/stat.h>
  31. #endif
  32. #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
  33. #else
  34. /* Normal invocation convention. */
  35. #ifndef _@GUARD_PREFIX@_FCNTL_H
  36. /* Needed before <sys/stat.h>.
  37. May also define off_t to a 64-bit type on native Windows. */
  38. #include <sys/types.h>
  39. /* On some systems other than glibc, <sys/stat.h> is a prerequisite of
  40. <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
  41. But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
  42. extern "C" { ... } block, which leads to errors in C++ mode with the
  43. overridden <sys/stat.h> from gnulib. These errors are known to be gone
  44. with g++ version >= 4.3. */
  45. #if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
  46. # include <sys/stat.h>
  47. #endif
  48. /* The include_next requires a split double-inclusion guard. */
  49. #@INCLUDE_NEXT@ @NEXT_FCNTL_H@
  50. #ifndef _@GUARD_PREFIX@_FCNTL_H
  51. #define _@GUARD_PREFIX@_FCNTL_H
  52. #ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
  53. # include <unistd.h>
  54. #endif
  55. /* Native Windows platforms declare open(), creat() in <io.h>. */
  56. #if (@GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \
  57. && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
  58. # include <io.h>
  59. #endif
  60. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  61. /* The definition of _GL_ARG_NONNULL is copied here. */
  62. /* The definition of _GL_WARN_ON_USE is copied here. */
  63. /* Declare overridden functions. */
  64. #if @GNULIB_FCNTL@
  65. # if @REPLACE_FCNTL@
  66. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  67. # undef fcntl
  68. # define fcntl rpl_fcntl
  69. # endif
  70. _GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
  71. _GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
  72. # else
  73. # if !@HAVE_FCNTL@
  74. _GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
  75. # endif
  76. _GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
  77. # endif
  78. _GL_CXXALIASWARN (fcntl);
  79. #elif defined GNULIB_POSIXCHECK
  80. # undef fcntl
  81. # if HAVE_RAW_DECL_FCNTL
  82. _GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
  83. "use gnulib module fcntl for portability");
  84. # endif
  85. #endif
  86. #if @GNULIB_OPEN@
  87. # if @REPLACE_OPEN@
  88. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  89. # undef open
  90. # define open rpl_open
  91. # endif
  92. _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
  93. _GL_ARG_NONNULL ((1)));
  94. _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
  95. # else
  96. _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
  97. # endif
  98. /* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
  99. default argument. _GL_CXXALIASWARN does not work in this case. */
  100. # if !defined __hpux
  101. _GL_CXXALIASWARN (open);
  102. # endif
  103. #elif defined GNULIB_POSIXCHECK
  104. # undef open
  105. /* Assume open is always declared. */
  106. _GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
  107. "use gnulib module open for portability");
  108. #endif
  109. #if @GNULIB_OPENAT@
  110. # if @REPLACE_OPENAT@
  111. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  112. # undef openat
  113. # define openat rpl_openat
  114. # endif
  115. _GL_FUNCDECL_RPL (openat, int,
  116. (int fd, char const *file, int flags, /* mode_t mode */ ...)
  117. _GL_ARG_NONNULL ((2)));
  118. _GL_CXXALIAS_RPL (openat, int,
  119. (int fd, char const *file, int flags, /* mode_t mode */ ...));
  120. # else
  121. # if !@HAVE_OPENAT@
  122. _GL_FUNCDECL_SYS (openat, int,
  123. (int fd, char const *file, int flags, /* mode_t mode */ ...)
  124. _GL_ARG_NONNULL ((2)));
  125. # endif
  126. _GL_CXXALIAS_SYS (openat, int,
  127. (int fd, char const *file, int flags, /* mode_t mode */ ...));
  128. # endif
  129. _GL_CXXALIASWARN (openat);
  130. #elif defined GNULIB_POSIXCHECK
  131. # undef openat
  132. # if HAVE_RAW_DECL_OPENAT
  133. _GL_WARN_ON_USE (openat, "openat is not portable - "
  134. "use gnulib module openat for portability");
  135. # endif
  136. #endif
  137. /* Fix up the FD_* macros, only known to be missing on mingw. */
  138. #ifndef FD_CLOEXEC
  139. # define FD_CLOEXEC 1
  140. #endif
  141. /* Fix up the supported F_* macros. Intentionally leave other F_*
  142. macros undefined. Only known to be missing on mingw. */
  143. #ifndef F_DUPFD_CLOEXEC
  144. # define F_DUPFD_CLOEXEC 0x40000000
  145. /* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
  146. # define GNULIB_defined_F_DUPFD_CLOEXEC 1
  147. #else
  148. # define GNULIB_defined_F_DUPFD_CLOEXEC 0
  149. #endif
  150. #ifndef F_DUPFD
  151. # define F_DUPFD 1
  152. #endif
  153. #ifndef F_GETFD
  154. # define F_GETFD 2
  155. #endif
  156. /* Fix up the O_* macros. */
  157. #if !defined O_DIRECT && defined O_DIRECTIO
  158. /* Tru64 spells it 'O_DIRECTIO'. */
  159. # define O_DIRECT O_DIRECTIO
  160. #endif
  161. #if !defined O_CLOEXEC && defined O_NOINHERIT
  162. /* Mingw spells it 'O_NOINHERIT'. */
  163. # define O_CLOEXEC O_NOINHERIT
  164. #endif
  165. #ifndef O_CLOEXEC
  166. # define O_CLOEXEC 0
  167. #endif
  168. #ifndef O_DIRECT
  169. # define O_DIRECT 0
  170. #endif
  171. #ifndef O_DIRECTORY
  172. # define O_DIRECTORY 0
  173. #endif
  174. #ifndef O_DSYNC
  175. # define O_DSYNC 0
  176. #endif
  177. #ifndef O_EXEC
  178. # define O_EXEC O_RDONLY /* This is often close enough in older systems. */
  179. #endif
  180. #ifndef O_IGNORE_CTTY
  181. # define O_IGNORE_CTTY 0
  182. #endif
  183. #ifndef O_NDELAY
  184. # define O_NDELAY 0
  185. #endif
  186. #ifndef O_NOATIME
  187. # define O_NOATIME 0
  188. #endif
  189. #ifndef O_NONBLOCK
  190. # define O_NONBLOCK O_NDELAY
  191. #endif
  192. /* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
  193. value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
  194. or to 0 as fallback. */
  195. #if @GNULIB_NONBLOCKING@
  196. # if O_NONBLOCK
  197. # define GNULIB_defined_O_NONBLOCK 0
  198. # else
  199. # define GNULIB_defined_O_NONBLOCK 1
  200. # undef O_NONBLOCK
  201. # define O_NONBLOCK 0x40000000
  202. # endif
  203. #endif
  204. #ifndef O_NOCTTY
  205. # define O_NOCTTY 0
  206. #endif
  207. #ifndef O_NOFOLLOW
  208. # define O_NOFOLLOW 0
  209. #endif
  210. #ifndef O_NOLINK
  211. # define O_NOLINK 0
  212. #endif
  213. #ifndef O_NOLINKS
  214. # define O_NOLINKS 0
  215. #endif
  216. #ifndef O_NOTRANS
  217. # define O_NOTRANS 0
  218. #endif
  219. #ifndef O_RSYNC
  220. # define O_RSYNC 0
  221. #endif
  222. #ifndef O_SEARCH
  223. # define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
  224. #endif
  225. #ifndef O_SYNC
  226. # define O_SYNC 0
  227. #endif
  228. #ifndef O_TTY_INIT
  229. # define O_TTY_INIT 0
  230. #endif
  231. #if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
  232. # undef O_ACCMODE
  233. # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
  234. #endif
  235. /* For systems that distinguish between text and binary I/O.
  236. O_BINARY is usually declared in fcntl.h */
  237. #if !defined O_BINARY && defined _O_BINARY
  238. /* For MSC-compatible compilers. */
  239. # define O_BINARY _O_BINARY
  240. # define O_TEXT _O_TEXT
  241. #endif
  242. #if defined __BEOS__ || defined __HAIKU__
  243. /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
  244. # undef O_BINARY
  245. # undef O_TEXT
  246. #endif
  247. #ifndef O_BINARY
  248. # define O_BINARY 0
  249. # define O_TEXT 0
  250. #endif
  251. /* Fix up the AT_* macros. */
  252. /* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
  253. value exceeds INT_MAX, so its use as an int doesn't conform to the
  254. C standard, and GCC and Sun C complain in some cases. If the bug
  255. is present, undef AT_FDCWD here, so it can be redefined below. */
  256. #if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
  257. # undef AT_FDCWD
  258. #endif
  259. /* Use the same bit pattern as Solaris 9, but with the proper
  260. signedness. The bit pattern is important, in case this actually is
  261. Solaris with the above workaround. */
  262. #ifndef AT_FDCWD
  263. # define AT_FDCWD (-3041965)
  264. #endif
  265. /* Use the same values as Solaris 9. This shouldn't matter, but
  266. there's no real reason to differ. */
  267. #ifndef AT_SYMLINK_NOFOLLOW
  268. # define AT_SYMLINK_NOFOLLOW 4096
  269. #endif
  270. #ifndef AT_REMOVEDIR
  271. # define AT_REMOVEDIR 1
  272. #endif
  273. /* Solaris 9 lacks these two, so just pick unique values. */
  274. #ifndef AT_SYMLINK_FOLLOW
  275. # define AT_SYMLINK_FOLLOW 2
  276. #endif
  277. #ifndef AT_EACCESS
  278. # define AT_EACCESS 4
  279. #endif
  280. #endif /* _@GUARD_PREFIX@_FCNTL_H */
  281. #endif /* _@GUARD_PREFIX@_FCNTL_H */
  282. #endif