fcntl.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. # include <sys/stat.h>
  29. #endif
  30. #ifdef __USE_MISC
  31. # ifndef R_OK /* Verbatim from <unistd.h>. Ugh. */
  32. /* Values for the second argument to access.
  33. These may be OR'd together. */
  34. # define R_OK 4 /* Test for read permission. */
  35. # define W_OK 2 /* Test for write permission. */
  36. # define X_OK 1 /* Test for execute permission. */
  37. # define F_OK 0 /* Test for existence. */
  38. # endif
  39. #endif /* Use misc. */
  40. /* XPG wants the following symbols. */
  41. #ifdef __USE_XOPEN /* <stdio.h> has the same definitions. */
  42. # define SEEK_SET 0 /* Seek from beginning of file. */
  43. # define SEEK_CUR 1 /* Seek from current position. */
  44. # define SEEK_END 2 /* Seek from end of file. */
  45. #endif /* XPG */
  46. #ifdef __USE_ATFILE
  47. # define AT_FDCWD -100 /* Special value used to indicate
  48. the *at functions should use the
  49. current working directory. */
  50. # define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
  51. # define AT_REMOVEDIR 0x200 /* Remove directory instead of
  52. unlinking file. */
  53. # define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
  54. # define AT_EACCESS 0x200 /* Test access permitted for
  55. effective IDs, not real IDs. */
  56. #endif
  57. /* Do the file control operation described by CMD on FD.
  58. The remaining arguments are interpreted depending on CMD.
  59. This function is a cancellation point and therefore not marked with
  60. __THROW. */
  61. #if !defined(__USE_FILE_OFFSET64) || defined(__LP64__)
  62. extern int fcntl (int __fd, int __cmd, ...);
  63. # ifdef _LIBC
  64. extern int __fcntl_nocancel(int, int, long) attribute_hidden;
  65. libc_hidden_proto(fcntl)
  66. # endif
  67. #else
  68. # ifdef __REDIRECT
  69. extern int __REDIRECT (fcntl, (int __fd, int __cmd, ...), fcntl64);
  70. # else
  71. # define fcntl fcntl64
  72. # endif
  73. #endif
  74. #if defined(__USE_LARGEFILE64) && !defined(__LP64__)
  75. extern int fcntl64 (int __fd, int __cmd, ...);
  76. # ifdef _LIBC
  77. extern int __fcntl64_nocancel(int, int, long) attribute_hidden;
  78. libc_hidden_proto(fcntl64)
  79. # endif
  80. #endif
  81. /* Open FILE and return a new file descriptor for it, or -1 on error.
  82. OFLAG determines the type of access used. If O_CREAT is on OFLAG,
  83. the third argument is taken as a `mode_t', the mode of the created file.
  84. This function is a cancellation point and therefore not marked with
  85. __THROW. */
  86. #ifndef __USE_FILE_OFFSET64
  87. extern int open (const char *__file, int __oflag, ...) __nonnull ((1));
  88. libc_hidden_proto(open)
  89. # ifdef _LIBC
  90. extern int __open2_nocancel(const char *, int) __nonnull ((1)) attribute_hidden;
  91. extern int __open_nocancel(const char *, int, mode_t) __nonnull ((1)) attribute_hidden;
  92. # endif
  93. #else
  94. # ifdef __REDIRECT
  95. extern int __REDIRECT (open, (const char *__file, int __oflag, ...), open64)
  96. __nonnull ((1));
  97. # else
  98. # define open open64
  99. # endif
  100. #endif
  101. #ifdef __USE_LARGEFILE64
  102. extern int open64 (const char *__file, int __oflag, ...) __nonnull ((1));
  103. libc_hidden_proto(open64)
  104. #endif
  105. #ifdef __USE_ATFILE
  106. /* Similar to `open' but a relative path name is interpreted relative to
  107. the directory for which FD is a descriptor.
  108. NOTE: some other `openat' implementation support additional functionality
  109. through this interface, especially using the O_XATTR flag. This is not
  110. yet supported here.
  111. This function is a cancellation point and therefore not marked with
  112. __THROW. */
  113. # ifndef __USE_FILE_OFFSET64
  114. extern int openat (int __fd, const char *__file, int __oflag, ...)
  115. __nonnull ((2));
  116. libc_hidden_proto(openat)
  117. # else
  118. # ifdef __REDIRECT
  119. extern int __REDIRECT (openat, (int __fd, const char *__file, int __oflag,
  120. ...), openat64) __nonnull ((2));
  121. # else
  122. # define openat openat64
  123. # endif
  124. # endif
  125. extern int openat64 (int __fd, const char *__file, int __oflag, ...)
  126. __nonnull ((2));
  127. #endif
  128. /* Create and open FILE, with mode MODE. This takes an `int' MODE
  129. argument because that is what `mode_t' will be widened to.
  130. This function is a cancellation point and therefore not marked with
  131. __THROW. */
  132. #ifndef __USE_FILE_OFFSET64
  133. extern int creat (const char *__file, __mode_t __mode) __nonnull ((1));
  134. #else
  135. # ifdef __REDIRECT
  136. extern int __REDIRECT (creat, (const char *__file, __mode_t __mode),
  137. creat64) __nonnull ((1));
  138. # else
  139. # define creat creat64
  140. # endif
  141. #endif
  142. #ifdef __USE_LARGEFILE64
  143. extern int creat64 (const char *__file, __mode_t __mode) __nonnull ((1));
  144. #endif
  145. #if !defined F_LOCK && (defined __USE_MISC || (defined __USE_XOPEN_EXTENDED \
  146. && !defined __USE_POSIX))
  147. /* NOTE: These declarations also appear in <unistd.h>; be sure to keep both
  148. files consistent. Some systems have them there and some here, and some
  149. software depends on the macros being defined without including both. */
  150. /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
  151. LEN is always relative to the current file position.
  152. The CMD argument is one of the following. */
  153. # define F_ULOCK 0 /* Unlock a previously locked region. */
  154. # define F_LOCK 1 /* Lock a region for exclusive use. */
  155. # define F_TLOCK 2 /* Test and lock a region for exclusive use. */
  156. # define F_TEST 3 /* Test a region for other processes locks. */
  157. # ifndef __USE_FILE_OFFSET64
  158. extern int lockf (int __fd, int __cmd, __off_t __len);
  159. libc_hidden_proto(lockf)
  160. # else
  161. # ifdef __REDIRECT
  162. extern int __REDIRECT (lockf, (int __fd, int __cmd, __off64_t __len), lockf64);
  163. # else
  164. # define lockf lockf64
  165. # endif
  166. # endif
  167. # ifdef __USE_LARGEFILE64
  168. extern int lockf64 (int __fd, int __cmd, __off64_t __len);
  169. # endif
  170. #endif
  171. #if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
  172. /* Advice the system about the expected behaviour of the application with
  173. respect to the file associated with FD. */
  174. # ifndef __USE_FILE_OFFSET64
  175. extern int posix_fadvise (int __fd, __off_t __offset, __off_t __len,
  176. int __advise) __THROW;
  177. # else
  178. # ifdef __REDIRECT_NTH
  179. extern int __REDIRECT_NTH (posix_fadvise, (int __fd, __off64_t __offset,
  180. __off64_t __len, int __advise),
  181. posix_fadvise64);
  182. # else
  183. # define posix_fadvise posix_fadvise64
  184. # endif
  185. # endif
  186. # ifdef __USE_LARGEFILE64
  187. extern int posix_fadvise64 (int __fd, __off64_t __offset, __off64_t __len,
  188. int __advise) __THROW;
  189. # endif
  190. #endif
  191. #if 0 /* && defined __UCLIBC_HAS_ADVANCED_REALTIME__ */
  192. /* FIXME -- uClibc should probably implement these... */
  193. /* Reserve storage for the data of the file associated with FD.
  194. This function is a possible cancellation points and therefore not
  195. marked with __THROW. */
  196. # ifndef __USE_FILE_OFFSET64
  197. extern int posix_fallocate (int __fd, __off_t __offset, __off_t __len);
  198. # else
  199. # ifdef __REDIRECT
  200. extern int __REDIRECT (posix_fallocate, (int __fd, __off64_t __offset,
  201. __off64_t __len),
  202. posix_fallocate64);
  203. # else
  204. # define posix_fallocate posix_fallocate64
  205. # endif
  206. # endif
  207. # ifdef __USE_LARGEFILE64
  208. extern int posix_fallocate64 (int __fd, __off64_t __offset, __off64_t __len);
  209. # endif
  210. #endif
  211. __END_DECLS
  212. #endif /* fcntl.h */