fcntl.in.h 8.8 KB

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