_default_fcntl.h 6.8 KB

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