fcntl.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* Copyright (C) 1991,1992,1994-2001,2003,2004,2005,2006,2007, 2009
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. /*
  16. * POSIX Standard: 6.5 File Control Operations <fcntl.h>
  17. */
  18. #ifndef _FCNTL_H
  19. #define _FCNTL_H 1
  20. #include <features.h>
  21. /* This must be early so <bits/fcntl.h> can define types winningly. */
  22. __BEGIN_DECLS
  23. /* Get the definitions of O_*, F_*, FD_*: all the
  24. numbers and flag bits for `open', `fcntl', et al. */
  25. #include <bits/fcntl.h>
  26. /* For XPG all symbols from <sys/stat.h> should also be available. */
  27. #ifdef __USE_XOPEN
  28. # ifdef __USE_XOPEN2K8
  29. # define __need_timespec
  30. # endif
  31. # include <sys/stat.h>
  32. #endif
  33. #ifdef __USE_MISC
  34. # ifndef R_OK /* Verbatim from <unistd.h>. Ugh. */
  35. /* Values for the second argument to access.
  36. These may be OR'd together. */
  37. # define R_OK 4 /* Test for read permission. */
  38. # define W_OK 2 /* Test for write permission. */
  39. # define X_OK 1 /* Test for execute permission. */
  40. # define F_OK 0 /* Test for existence. */
  41. # endif
  42. #endif /* Use misc. */
  43. /* XPG wants the following symbols. */
  44. #ifdef __USE_XOPEN /* <stdio.h> has the same definitions. */
  45. # define SEEK_SET 0 /* Seek from beginning of file. */
  46. # define SEEK_CUR 1 /* Seek from current position. */
  47. # define SEEK_END 2 /* Seek from end of file. */
  48. #endif /* XPG */
  49. #ifdef __USE_ATFILE
  50. # define AT_FDCWD -100 /* Special value used to indicate
  51. the *at functions should use the
  52. current working directory. */
  53. # define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
  54. # define AT_REMOVEDIR 0x200 /* Remove directory instead of
  55. unlinking file. */
  56. # define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
  57. # ifdef __USE_GNU
  58. # define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount
  59. traversal. */
  60. # define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname. */
  61. # endif
  62. # define AT_EACCESS 0x200 /* Test access permitted for
  63. effective IDs, not real IDs. */
  64. #endif
  65. /* Do the file control operation described by CMD on FD.
  66. The remaining arguments are interpreted depending on CMD.
  67. This function is a cancellation point and therefore not marked with
  68. __THROW. */
  69. #if !defined(__USE_FILE_OFFSET64) || defined(__LP64__)
  70. extern int fcntl (int __fd, int __cmd, ...);
  71. # ifdef _LIBC
  72. extern int __fcntl_nocancel(int, int, long) attribute_hidden;
  73. libc_hidden_proto(fcntl)
  74. # endif
  75. #else
  76. # ifdef __REDIRECT
  77. extern int __REDIRECT (fcntl, (int __fd, int __cmd, ...), fcntl64);
  78. # else
  79. # define fcntl fcntl64
  80. # endif
  81. #endif
  82. #if defined(__USE_LARGEFILE64) && !defined(__LP64__)
  83. extern int fcntl64 (int __fd, int __cmd, ...);
  84. # ifdef _LIBC
  85. extern int __fcntl64_nocancel(int, int, long) attribute_hidden;
  86. libc_hidden_proto(fcntl64)
  87. # endif
  88. #endif
  89. /* Open FILE and return a new file descriptor for it, or -1 on error.
  90. OFLAG determines the type of access used. If O_CREAT is on OFLAG,
  91. the third argument is taken as a `mode_t', the mode of the created file.
  92. This function is a cancellation point and therefore not marked with
  93. __THROW. */
  94. #ifndef __USE_FILE_OFFSET64
  95. extern int open (const char *__file, int __oflag, ...) __nonnull ((1));
  96. libc_hidden_proto(open)
  97. # ifdef _LIBC
  98. extern int __open2_nocancel(const char *, int) __nonnull ((1)) attribute_hidden;
  99. extern int __open_nocancel(const char *, int, mode_t) __nonnull ((1)) attribute_hidden;
  100. # endif
  101. #else
  102. # ifdef __REDIRECT
  103. extern int __REDIRECT (open, (const char *__file, int __oflag, ...), open64)
  104. __nonnull ((1));
  105. # else
  106. # define open open64
  107. # endif
  108. #endif
  109. #ifdef __USE_LARGEFILE64
  110. extern int open64 (const char *__file, int __oflag, ...) __nonnull ((1));
  111. libc_hidden_proto(open64)
  112. #endif
  113. #ifdef __USE_ATFILE
  114. /* Similar to `open' but a relative path name is interpreted relative to
  115. the directory for which FD is a descriptor.
  116. NOTE: some other `openat' implementation support additional functionality
  117. through this interface, especially using the O_XATTR flag. This is not
  118. yet supported here.
  119. This function is a cancellation point and therefore not marked with
  120. __THROW. */
  121. # ifndef __USE_FILE_OFFSET64
  122. extern int openat (int __fd, const char *__file, int __oflag, ...)
  123. __nonnull ((2));
  124. libc_hidden_proto(openat)
  125. # else
  126. # ifdef __REDIRECT
  127. extern int __REDIRECT (openat, (int __fd, const char *__file, int __oflag,
  128. ...), openat64) __nonnull ((2));
  129. # else
  130. # define openat openat64
  131. # endif
  132. # endif
  133. extern int openat64 (int __fd, const char *__file, int __oflag, ...)
  134. __nonnull ((2));
  135. #endif
  136. /* Create and open FILE, with mode MODE. This takes an `int' MODE
  137. argument because that is what `mode_t' will be widened to.
  138. This function is a cancellation point and therefore not marked with
  139. __THROW. */
  140. #ifndef __USE_FILE_OFFSET64
  141. extern int creat (const char *__file, __mode_t __mode) __nonnull ((1));
  142. #else
  143. # ifdef __REDIRECT
  144. extern int __REDIRECT (creat, (const char *__file, __mode_t __mode),
  145. creat64) __nonnull ((1));
  146. # else
  147. # define creat creat64
  148. # endif
  149. #endif
  150. #ifdef __USE_LARGEFILE64
  151. extern int creat64 (const char *__file, __mode_t __mode) __nonnull ((1));
  152. #endif
  153. #if !defined F_LOCK && (defined __USE_MISC || (defined __USE_XOPEN_EXTENDED \
  154. && !defined __USE_POSIX))
  155. /* NOTE: These declarations also appear in <unistd.h>; be sure to keep both
  156. files consistent. Some systems have them there and some here, and some
  157. software depends on the macros being defined without including both. */
  158. /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
  159. LEN is always relative to the current file position.
  160. The CMD argument is one of the following. */
  161. # define F_ULOCK 0 /* Unlock a previously locked region. */
  162. # define F_LOCK 1 /* Lock a region for exclusive use. */
  163. # define F_TLOCK 2 /* Test and lock a region for exclusive use. */
  164. # define F_TEST 3 /* Test a region for other processes locks. */
  165. # ifndef __USE_FILE_OFFSET64
  166. extern int lockf (int __fd, int __cmd, __off_t __len);
  167. libc_hidden_proto(lockf)
  168. # else
  169. # ifdef __REDIRECT
  170. extern int __REDIRECT (lockf, (int __fd, int __cmd, __off64_t __len), lockf64);
  171. # else
  172. # define lockf lockf64
  173. # endif
  174. # endif
  175. # ifdef __USE_LARGEFILE64
  176. extern int lockf64 (int __fd, int __cmd, __off64_t __len);
  177. # endif
  178. #endif
  179. #if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
  180. /* Advice the system about the expected behaviour of the application with
  181. respect to the file associated with FD. */
  182. # ifndef __USE_FILE_OFFSET64
  183. extern int posix_fadvise (int __fd, __off_t __offset, __off_t __len,
  184. int __advise) __THROW;
  185. # else
  186. # ifdef __REDIRECT_NTH
  187. extern int __REDIRECT_NTH (posix_fadvise, (int __fd, __off64_t __offset,
  188. __off64_t __len, int __advise),
  189. posix_fadvise64);
  190. # else
  191. # define posix_fadvise posix_fadvise64
  192. # endif
  193. # endif
  194. # ifdef __USE_LARGEFILE64
  195. extern int posix_fadvise64 (int __fd, __off64_t __offset, __off64_t __len,
  196. int __advise) __THROW;
  197. # endif
  198. #endif
  199. #if defined __UCLIBC_HAS_ADVANCED_REALTIME__
  200. /* Reserve storage for the data of the file associated with FD.
  201. This function is a possible cancellation point and therefore not
  202. marked with __THROW. */
  203. # ifndef __USE_FILE_OFFSET64
  204. extern int posix_fallocate (int __fd, __off_t __offset, __off_t __len);
  205. # else
  206. # ifdef __REDIRECT
  207. extern int __REDIRECT (posix_fallocate, (int __fd, __off64_t __offset,
  208. __off64_t __len),
  209. posix_fallocate64);
  210. # else
  211. # define posix_fallocate posix_fallocate64
  212. # endif
  213. # endif
  214. # ifdef __USE_LARGEFILE64
  215. extern int posix_fallocate64 (int __fd, __off64_t __offset, __off64_t __len);
  216. # endif
  217. #endif
  218. #if (defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU) || defined _LIBC
  219. /* Reserve storage for the data of a file associated with FD. This function
  220. is Linux-specific. For the portable version, use posix_fallocate().
  221. Unlike the latter, fallocate can operate in different modes. The default
  222. mode = 0 is equivalent to posix_fallocate().
  223. Note: These declarations are used in posix_fallocate.c and
  224. posix_fallocate64.c, so we expose them internally.
  225. */
  226. /* Flags for fallocate's mode. */
  227. # define FALLOC_FL_KEEP_SIZE 1 /* Don't extend size of file
  228. even if offset + len is
  229. greater than file size. */
  230. # define FALLOC_FL_PUNCH_HOLE 2 /* Create a hole in the file. */
  231. # ifndef __USE_FILE_OFFSET64
  232. extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len);
  233. # else
  234. # ifdef __REDIRECT
  235. extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset,
  236. __off64_t __len),
  237. fallocate64);
  238. # else
  239. # define fallocate fallocate64
  240. # endif
  241. # endif
  242. # ifdef __USE_LARGEFILE64
  243. extern int fallocate64 (int __fd, int __mode, __off64_t __offset, __off64_t __len);
  244. # endif
  245. #endif
  246. __END_DECLS
  247. #endif /* fcntl.h */