_default_fcntl.h 7.0 KB

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