home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !gcc / include / libscl / h / fcntl < prev    next >
Encoding:
Text File  |  2004-09-05  |  4.5 KB  |  171 lines

  1. /* unistd.h.
  2.  
  3.    This header is not part of the normal SharedCLibrary but is
  4.    provided here for compatibility with the GNU C++ libraries.
  5.    Copyright (c) 1999 Nick Burrett.  */
  6.  
  7. #ifndef __FCNTL_H
  8. #define __FCNTL_H
  9.  
  10. #ifndef __SYS_TYPES_H
  11. #include <sys/types.h>
  12. #endif
  13.  
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17.  
  18. /* File access modes for open() and fcntl()  */
  19.  
  20. /* These fcntlbits are derived from BSD 4.4 */
  21.  
  22. #define O_RDONLY 0 /* Open for read only.  */
  23. #define O_WRONLY 1 /* Open for write only.  */
  24. #define O_RDWR 2 /* Open for read/write.  */
  25.  
  26. /* Mask for file access modes.  */
  27. #define    O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
  28.  
  29. /* Bits OR'd into the second argument to open.  */
  30.  
  31. /* Create file if it doesn't exist.  */
  32. #define O_CREAT     0x0200
  33. /* Fail if file already exists.  */
  34. #define O_EXCL        0x0800
  35. /* Truncate file to zero length.  */
  36. #define O_TRUNC            0x0400
  37. /* Send SIGIO to owner when data is ready.  */
  38. #define O_ASYNC        0x0040
  39. /* Synchronous writes.  */
  40. #define O_FSYNC        0x0080
  41. #define O_SYNC        O_FSYNC
  42. /* Open with shared file lock.  */
  43. #define O_SHLOCK    0x0010
  44. /* Open with shared exclusive lock.  */
  45. #define O_EXLOCK    0x0020
  46.  
  47. /* File status flags for open and fcntl.  */
  48.  
  49. /* Writes append to the file.  */
  50. #define O_APPEND    0x0008
  51. /* Non-blocking I/O.  */
  52. #define O_NONBLOCK      0x0004
  53. #define O_NDELAY    O_NONBLOCK
  54.  
  55. /* close on exec() flag - must be bit 8 */
  56. #define O_EXECCL    0x0100
  57.  
  58. /* Strict POSIX doesn't allow this. */
  59. #define O_BINARY    0x2000
  60. #define O_TEXT        0x1000
  61.  
  62. #define O_PIPE        0x4000 /* UnixLib specific */
  63. #define O_UNLINKED    0x8000 /* UnixLib specific - unlink file on close */
  64.  
  65.  
  66.  
  67. /* Duplicate file descriptor.  */
  68. #define F_DUPFD     0
  69. /* Return file descriptor flags.  */
  70. #define F_GETFD     1
  71. /* Set file descriptor flags.  */
  72. #define F_SETFD     2
  73. /* Read file status flags.  */
  74. #define F_GETFL     3
  75. /* Set file status flags.  */
  76. #define F_SETFL     4
  77. /* Get owner (receiver of SIGIO).  */
  78. #define F_GETOWN        5
  79. /* Set owner (receiver of SIGIO).  */
  80. #define F_SETOWN        6
  81. /* Get record locking info.  */
  82. #define F_GETLK            7
  83. /* Set record locking info (non-blocking).  */
  84. #define F_SETLK        8
  85. /* Set record locking info (blocking).  */
  86. #define F_SETLKW    9
  87. /* Get unlink on close (UnixLib internal - currently implements tmpfile). */
  88. #define F_GETUNL    10
  89. /* Set unlink on close (could be used to emulate open() then unlink trick). */
  90. #define F_SETUNL    11
  91.  
  92. /* Bits in the file status flags returned by F_GETFL.  */
  93. #define FREAD        1
  94. #define    FWRITE        2
  95.  
  96. /* Traditional BSD names the O_* bits.  */
  97. #define FASYNC        O_ASYNC
  98. #define FCREAT        O_CREAT
  99. #define FEXCL        O_EXCL
  100. #define FTRUNC        O_TRUNC
  101. #define FNOCTTY        O_NOCTTY
  102. #define FFSYNC        O_FSYNC
  103. #define FSYNC        O_SYNC
  104. #define FAPPEND        O_APPEND
  105. #define FNONBLOCK    O_NONBLOCK
  106. #define FNDELAY        O_NDELAY
  107.  
  108.  
  109. /* If set, cause the file descriptor to be closed if an exec function
  110.    is used.  Initially, set clear.  */
  111. #define FD_CLOEXEC    O_EXECCL
  112.  
  113. /* The structure describing an advisory lock.  This is the type of the third
  114.    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
  115. struct flock
  116.   {
  117.     /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
  118.     short int l_type;
  119.     /* Where `l_start' is relative to (like `lseek').  */
  120.     short int l_whence;
  121.     /* Offset where the lock begins.  */
  122.     __off_t l_start;
  123.     /* Size of the locked area; zero means until EOF.  */
  124.     __off_t l_len;
  125.     /* Process holding the lock.  */
  126.     short int l_pid;
  127.   };
  128.  
  129. /* Values for the `l_type' field of a `struct flock'.  */
  130. #define    F_RDLCK    1    /* Read lock.  */
  131. #define    F_WRLCK    2    /* Write lock.  */
  132. #define    F_UNLCK    3    /* Remove lock.  */
  133.  
  134.  
  135. #ifndef    R_OK
  136. /* Straight from <unistd.h>.  */
  137.  
  138. /* Values for the second argument to access.
  139.    These may be OR'd together.  */
  140.  
  141. /* Test for read permission.  */
  142. #define    R_OK    4
  143. /* Test for write permission.  */
  144. #define    W_OK    2
  145. /* Test for execute permission.  */
  146. #define    X_OK    1
  147. /* Test for existence.  */
  148. #define    F_OK    0
  149. #endif
  150.  
  151.  
  152. /* Do the file control operation described by CMD on FD.
  153.    The remaining arguments are interpreted depending on CMD.  */
  154. extern int fcntl (int fd, int cmd, ...);
  155.  
  156. /* Open FILE and return a new file descriptor for it, or -1 on error.
  157.    OFLAG determines the type of access used.  If O_CREAT is on OFLAG,
  158.    the third argument is taken as a `mode_t', the mode of the created file.  */
  159. extern int open (const char *file, int oflag, ...);
  160.  
  161. /* Create and open FILE, with mode MODE.
  162.    This takes an `int' MODE argument because that is
  163.    what `mode_t' will be widened to.  */
  164. extern int creat (const char *file, __mode_t mode);
  165.  
  166. #ifdef __cplusplus
  167.     }
  168. #endif
  169.  
  170. #endif
  171.