home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue6 / SDL.ZIP / !gcc / include / unixlib / h / fcntl < prev    next >
Encoding:
Text File  |  2006-09-17  |  5.9 KB  |  225 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/fcntl.h,v $
  4.  * $Date: 2004/10/17 16:24:43 $
  5.  * $Revision: 1.7 $
  6.  * $State: Exp $
  7.  * $Author: joty $
  8.  *
  9.  *
  10.  ***************************************************************************/
  11.  
  12. /* POSIX Standard 6.5: File Control Operations <fcntl.h> */
  13.  
  14. #ifndef __FCNTL_H
  15. #define __FCNTL_H
  16.  
  17. #ifndef __UNIXLIB_FEATURES_H
  18. #include <features.h>
  19. #endif
  20.  
  21. #ifndef __UNIXLIB_TYPES_H
  22. #include <unixlib/types.h>
  23. #endif
  24.  
  25. #ifdef __USE_XOPEN
  26. #include <sys/stat.h>
  27. #endif
  28.  
  29. __BEGIN_DECLS
  30.  
  31. /* File access modes for open() and fcntl()  */
  32.  
  33. #if 0
  34. /* These fcntlbits are derived from POSIX.1  */
  35.  
  36. #define O_OMASK 3
  37. #define O_RDONLY 0x0001
  38. #define O_WRONLY 0x0002
  39. #define O_RDWR (O_RDONLY | O_WRONLY)
  40. #define    O_ACCMODE O_RDWR
  41.  
  42. /* Open for exec.  */
  43. #define O_EXEC 0x0004
  44. #define O_READ O_RDONLY
  45. #define O_WRITE O_WRONLY
  46.  
  47. #else
  48. /* These fcntlbits are derived from BSD 4.4 */
  49.  
  50. #define O_RDONLY 0 /* Open for read only.  */
  51. #define O_WRONLY 1 /* Open for write only.  */
  52. #define O_RDWR 2 /* Open for read/write.  */
  53.  
  54. /* Mask for file access modes.  */
  55. #define    O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
  56.  
  57. #endif
  58.  
  59. /* Bits OR'd into the second argument to open.  */
  60.  
  61. /* Create file if it doesn't exist.  */
  62. #define O_CREAT     0x0200
  63. /* Fail if file already exists.  */
  64. #define O_EXCL        0x0800
  65. /* Truncate file to zero length.  */
  66. #define O_TRUNC            0x0400
  67. /* Send SIGIO to owner when data is ready.  */
  68. #define O_ASYNC        0x0040
  69. /* Synchronous writes.  */
  70. #define O_FSYNC        0x0080
  71. #define O_SYNC        O_FSYNC
  72. /* Open with shared file lock.  */
  73. #define O_SHLOCK    0x0010
  74. /* Open with shared exclusive lock.  */
  75. #define O_EXLOCK    0x0020
  76.  
  77. /* File status flags for open and fcntl.  */
  78.  
  79. /* Writes append to the file.  */
  80. #define O_APPEND    0x0008
  81. /* Non-blocking I/O.  */
  82. #define O_NONBLOCK      0x0004
  83. #define O_NDELAY    O_NONBLOCK
  84.  
  85. /* close on exec() flag - must be bit 8 */
  86. #define O_EXECCL    0x0100
  87.  
  88. #ifndef _POSIX_SOURCE
  89. /* Strict POSIX doesn't allow this. */
  90. #define O_BINARY    0x2000
  91. #define O_TEXT        0x1000
  92. #endif
  93.  
  94. #define O_PIPE        0x4000 /* UnixLib specific */
  95. #define O_UNLINKED    0x8000 /* UnixLib specific - unlink file on close */
  96.  
  97. /* Don't make terminal device controlling terminal */
  98. #define O_NOCTTY       0x10000
  99.  
  100.  
  101. /* Duplicate file descriptor.  */
  102. #define F_DUPFD     0
  103. /* Return file descriptor flags.  */
  104. #define F_GETFD     1
  105. /* Set file descriptor flags.  */
  106. #define F_SETFD     2
  107. /* Read file status flags.  */
  108. #define F_GETFL     3
  109. /* Set file status flags.  */
  110. #define F_SETFL     4
  111. /* Get owner (receiver of SIGIO).  */
  112. #define F_GETOWN        5
  113. /* Set owner (receiver of SIGIO).  */
  114. #define F_SETOWN        6
  115. /* Get record locking info.  */
  116. #define F_GETLK            7
  117. /* Set record locking info (non-blocking).  */
  118. #define F_SETLK        8
  119. /* Set record locking info (blocking).  */
  120. #define F_SETLKW    9
  121. /* Get unlink on close (UnixLib internal - currently implements tmpfile). */
  122. #define F_GETUNL    10
  123. /* Set unlink on close (could be used to emulate open() then unlink trick). */
  124. #define F_SETUNL    11
  125.  
  126. /* Bits in the file status flags returned by F_GETFL.  */
  127. #define FREAD        1
  128. #define    FWRITE        2
  129.  
  130. /* Traditional BSD names the O_* bits.  */
  131. #define FASYNC        O_ASYNC
  132. #define FCREAT        O_CREAT
  133. #define FEXCL        O_EXCL
  134. #define FTRUNC        O_TRUNC
  135. #define FNOCTTY        O_NOCTTY
  136. #define FFSYNC        O_FSYNC
  137. #define FSYNC        O_SYNC
  138. #define FAPPEND        O_APPEND
  139. #define FNONBLOCK    O_NONBLOCK
  140. #define FNDELAY        O_NDELAY
  141.  
  142.  
  143. /* If set, cause the file descriptor to be closed if an exec function
  144.    is used.  Initially, set clear.  */
  145. #define FD_CLOEXEC    O_EXECCL
  146.  
  147. /* The structure describing an advisory lock.  This is the type of the third
  148.    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
  149. struct flock
  150.   {
  151.     /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
  152.     short int l_type;
  153.     /* Where `l_start' is relative to (like `lseek').  */
  154.     short int l_whence;
  155.     /* Offset where the lock begins.  */
  156.     __off_t l_start;
  157.     /* Size of the locked area; zero means until EOF.  */
  158.     __off_t l_len;
  159.     /* Process holding the lock.  */
  160.     short int l_pid;
  161.   };
  162.  
  163. /* Values for the `l_type' field of a `struct flock'.  */
  164. #define    F_RDLCK    1    /* Read lock.  */
  165. #define    F_WRLCK    2    /* Write lock.  */
  166. #define    F_UNLCK    3    /* Remove lock.  */
  167.  
  168.  
  169. #ifndef    R_OK
  170. /* Straight from <unistd.h>.  */
  171.  
  172. /* Values for the second argument to access.
  173.    These may be OR'd together.  */
  174.  
  175. /* Test for read permission.  */
  176. #define    R_OK    4
  177. /* Test for write permission.  */
  178. #define    W_OK    2
  179. /* Test for execute permission.  */
  180. #define    X_OK    1
  181. /* Test for existence.  */
  182. #define    F_OK    0
  183. #endif
  184.  
  185.  
  186. /* Do the file control operation described by CMD on FD.
  187.    The remaining arguments are interpreted depending on CMD.
  188.  
  189.    This is a cancellation point.  */
  190. extern int fcntl (int __fd, int __cmd, ...);
  191.  
  192. /* Open FILE and return a new file descriptor for it, or -1 on error.
  193.    OFLAG determines the type of access used.  If O_CREAT is on OFLAG,
  194.    the third argument is taken as a `mode_t', the mode of the created file.
  195.  
  196.    This is a cancellation point.  */
  197. extern int open (const char *file, int oflag, ...) __nonnull ((1));
  198.  
  199. /* Create and open FILE, with mode MODE.
  200.    This takes an `int' MODE argument because that is
  201.    what `mode_t' will be widened to.
  202.  
  203.    This is a cancellation point.  */
  204. extern int creat (const char *file, __mode_t mode) __nonnull ((1));
  205.  
  206. #ifndef F_LOCK
  207. /* These declarations also appear in <unistd.h>; be sure to keep both
  208.    files consistent.  */
  209.  
  210. /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
  211.    LEN is always relative to the current file position.
  212.    The CMD argument is one of the following.  */
  213.  
  214. #define F_ULOCK 0       /* Unlock a previously locked region.  */
  215. #define F_LOCK  1       /* Lock a region for exclusive use.  */
  216. #define F_TLOCK 2       /* Test and lock a region for exclusive use.  */
  217. #define F_TEST  3       /* Test a region for other processes locks.  */
  218.  
  219. extern int lockf (int fd, int cmd, __off_t len);
  220. #endif
  221.  
  222. __END_DECLS
  223.  
  224. #endif
  225.