_default_fcntl.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #ifndef _SYS__DEFAULT_FCNTL_H_
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #define _SYS__DEFAULT_FCNTL_H_
  6. #include <_ansi.h>
  7. #include <sys/cdefs.h>
  8. #define _FOPEN (-1) /* from sys/file.h, kernel use only */
  9. #define _FREAD 0x0001 /* read enabled */
  10. #define _FWRITE 0x0002 /* write enabled */
  11. #define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */
  12. #define _FMARK 0x0010 /* internal; mark during gc() */
  13. #define _FDEFER 0x0020 /* internal; defer for next gc pass */
  14. #define _FASYNC 0x0040 /* signal pgrp when data ready */
  15. #define _FSHLOCK 0x0080 /* BSD flock() shared lock present */
  16. #define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */
  17. #define _FCREAT 0x0200 /* open with file create */
  18. #define _FTRUNC 0x0400 /* open with truncation */
  19. #define _FEXCL 0x0800 /* error on open if file exists */
  20. #define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */
  21. #define _FSYNC 0x2000 /* do all writes synchronously */
  22. #define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
  23. #define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
  24. #define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
  25. #if defined (__CYGWIN__)
  26. #define _FBINARY 0x10000
  27. #define _FTEXT 0x20000
  28. #endif
  29. #define _FNOINHERIT 0x40000
  30. #define _FDIRECT 0x80000
  31. #define _FNOFOLLOW 0x100000
  32. #define _FDIRECTORY 0x200000
  33. #define _FEXECSRCH 0x400000
  34. #if defined (__CYGWIN__)
  35. #define _FTMPFILE 0x800000
  36. #define _FNOATIME 0x1000000
  37. #define _FPATH 0x2000000
  38. #endif
  39. #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
  40. /*
  41. * Flag values for open(2) and fcntl(2)
  42. * The kernel adds 1 to the open modes to turn it into some
  43. * combination of FREAD and FWRITE.
  44. */
  45. #define O_RDONLY 0 /* +1 == FREAD */
  46. #define O_WRONLY 1 /* +1 == FWRITE */
  47. #define O_RDWR 2 /* +1 == FREAD|FWRITE */
  48. #define O_APPEND _FAPPEND
  49. #define O_CREAT _FCREAT
  50. #define O_TRUNC _FTRUNC
  51. #define O_EXCL _FEXCL
  52. #define O_SYNC _FSYNC
  53. /* O_NDELAY _FNDELAY set in include/fcntl.h */
  54. /* O_NDELAY _FNBIO set in include/fcntl.h */
  55. #define O_NONBLOCK _FNONBLOCK
  56. #define O_NOCTTY _FNOCTTY
  57. /* POSIX-1.2008 specific flags */
  58. #if __POSIX_VISIBLE >= 200809
  59. #define O_CLOEXEC _FNOINHERIT
  60. #define O_NOFOLLOW _FNOFOLLOW
  61. #define O_DIRECTORY _FDIRECTORY
  62. #define O_EXEC _FEXECSRCH
  63. #define O_SEARCH _FEXECSRCH
  64. #endif
  65. #if __BSD_VISIBLE
  66. #define O_DIRECT _FDIRECT
  67. #endif
  68. #if defined (__CYGWIN__)
  69. #define O_BINARY _FBINARY
  70. #define O_TEXT _FTEXT
  71. #define O_DSYNC _FSYNC
  72. #define O_RSYNC _FSYNC
  73. /* Linux-specific flags */
  74. #if __GNU_VISIBLE
  75. #define O_TMPFILE _FTMPFILE
  76. #define O_NOATIME _FNOATIME
  77. #define O_PATH _FPATH
  78. #endif
  79. #endif
  80. #if __MISC_VISIBLE
  81. /*
  82. * Flags that work for fcntl(fd, F_SETFL, FXXXX)
  83. */
  84. #define FAPPEND _FAPPEND
  85. #define FSYNC _FSYNC
  86. #define FASYNC _FASYNC
  87. #define FNBIO _FNBIO
  88. #define FNONBIO _FNONBLOCK /* XXX fix to be NONBLOCK everywhere */
  89. #define FNDELAY _FNDELAY
  90. /*
  91. * Flags that are disallowed for fcntl's (FCNTLCANT);
  92. * used for opens, internal state, or locking.
  93. */
  94. #define FREAD _FREAD
  95. #define FWRITE _FWRITE
  96. #define FMARK _FMARK
  97. #define FDEFER _FDEFER
  98. #define FSHLOCK _FSHLOCK
  99. #define FEXLOCK _FEXLOCK
  100. /*
  101. * The rest of the flags, used only for opens
  102. */
  103. #define FOPEN _FOPEN
  104. #define FCREAT _FCREAT
  105. #define FTRUNC _FTRUNC
  106. #define FEXCL _FEXCL
  107. #define FNOCTTY _FNOCTTY
  108. #endif /* __MISC_VISIBLE */
  109. #if __BSD_VISIBLE
  110. #define FNONBLOCK _FNONBLOCK
  111. #endif /* __BSD_VISIBLE */
  112. /* XXX close on exec request; must match UF_EXCLOSE in user.h */
  113. #define FD_CLOEXEC 1 /* posix */
  114. /* fcntl(2) requests */
  115. #define F_DUPFD 0 /* Duplicate fildes */
  116. #define F_GETFD 1 /* Get fildes flags (close on exec) */
  117. #define F_SETFD 2 /* Set fildes flags (close on exec) */
  118. #define F_GETFL 3 /* Get file flags */
  119. #define F_SETFL 4 /* Set file flags */
  120. #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
  121. #define F_GETOWN 5 /* Get owner - for ASYNC */
  122. #define F_SETOWN 6 /* Set owner - for ASYNC */
  123. #endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 */
  124. #define F_GETLK 7 /* Get record-locking information */
  125. #define F_SETLK 8 /* Set or Clear a record-lock (Non-Blocking) */
  126. #define F_SETLKW 9 /* Set or Clear a record-lock (Blocking) */
  127. #if __MISC_VISIBLE
  128. #define F_RGETLK 10 /* Test a remote lock to see if it is blocked */
  129. #define F_RSETLK 11 /* Set or unlock a remote lock */
  130. #define F_CNVT 12 /* Convert a fhandle to an open fd */
  131. #define F_RSETLKW 13 /* Set or Clear remote record-lock(Blocking) */
  132. #endif /* __MISC_VISIBLE */
  133. #if __POSIX_VISIBLE >= 200809
  134. #define F_DUPFD_CLOEXEC 14 /* As F_DUPFD, but set close-on-exec flag */
  135. #endif
  136. /* fcntl(2) flags (l_type field of flock structure) */
  137. #define F_RDLCK 1 /* read lock */
  138. #define F_WRLCK 2 /* write lock */
  139. #define F_UNLCK 3 /* remove lock(s) */
  140. #if __MISC_VISIBLE
  141. #define F_UNLKSYS 4 /* remove remote locks for a given system */
  142. #endif /* __MISC_VISIBLE */
  143. #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
  144. /* Special descriptor value to denote the cwd in calls to openat(2) etc. */
  145. #define AT_FDCWD -2
  146. /* Flag values for faccessat2) et al. */
  147. #define AT_EACCESS 1
  148. #define AT_SYMLINK_NOFOLLOW 2
  149. #define AT_SYMLINK_FOLLOW 4
  150. #define AT_REMOVEDIR 8
  151. #if __GNU_VISIBLE
  152. #define AT_EMPTY_PATH 16
  153. #endif
  154. #endif
  155. #if __BSD_VISIBLE
  156. /* lock operations for flock(2) */
  157. #define LOCK_SH 0x01 /* shared file lock */
  158. #define LOCK_EX 0x02 /* exclusive file lock */
  159. #define LOCK_NB 0x04 /* don't block when locking */
  160. #define LOCK_UN 0x08 /* unlock file */
  161. #endif
  162. /*#include <sys/stdtypes.h>*/
  163. #ifndef __CYGWIN__
  164. /* file segment locking set data type - information passed to system by user */
  165. struct flock {
  166. short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */
  167. short l_whence; /* flag to choose starting offset */
  168. long l_start; /* relative offset, in bytes */
  169. long l_len; /* length, in bytes; 0 means lock to EOF */
  170. short l_pid; /* returned with F_GETLK */
  171. short l_xxx; /* reserved for future use */
  172. };
  173. #endif /* __CYGWIN__ */
  174. #if __MISC_VISIBLE
  175. /* extended file segment locking set data type */
  176. struct eflock {
  177. short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */
  178. short l_whence; /* flag to choose starting offset */
  179. long l_start; /* relative offset, in bytes */
  180. long l_len; /* length, in bytes; 0 means lock to EOF */
  181. short l_pid; /* returned with F_GETLK */
  182. short l_xxx; /* reserved for future use */
  183. long l_rpid; /* Remote process id wanting this lock */
  184. long l_rsys; /* Remote system id wanting this lock */
  185. };
  186. #endif /* __MISC_VISIBLE */
  187. #include <sys/types.h>
  188. #include <sys/stat.h> /* sigh. for the mode bits for open/creat */
  189. extern int open (const char *, int, ...);
  190. #if __ATFILE_VISIBLE
  191. extern int openat (int, const char *, int, ...);
  192. #endif
  193. extern int creat (const char *, mode_t);
  194. extern int fcntl (int, int, ...);
  195. #if __BSD_VISIBLE
  196. extern int flock (int, int);
  197. #endif
  198. #if __GNU_VISIBLE
  199. #include <sys/time.h>
  200. extern int futimesat (int, const char *, const struct timeval *);
  201. #endif
  202. /* Provide _<systemcall> prototypes for functions provided by some versions
  203. of newlib. */
  204. #ifdef _COMPILING_NEWLIB
  205. extern int _open (const char *, int, ...);
  206. extern int _fcntl (int, int, ...);
  207. #ifdef __LARGE64_FILES
  208. extern int _open64 (const char *, int, ...);
  209. #endif
  210. #endif
  211. #ifdef __cplusplus
  212. }
  213. #endif
  214. #endif /* !_SYS__DEFAULT_FCNTL_H_ */