fcntl.in.h 9.0 KB

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