fcntl.h 7.6 KB

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