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

  1. /* fcntl.h extension header for the RISC OS SharedCLibrary.
  2.    Copyright (c) 1997-2005 Nick Burrett
  3.    All rights reserved.
  4.  
  5.    Redistribution and use in source and binary forms, with or without
  6.    modification, are permitted provided that the following conditions
  7.    are met:
  8.    1. Redistributions of source code must retain the above copyright
  9.       notice, this list of conditions and the following disclaimer.
  10.    2. Redistributions in binary form must reproduce the above copyright
  11.       notice, this list of conditions and the following disclaimer in the
  12.       documentation and/or other materials provided with the distribution.
  13.    3. The name of the author may not be used to endorse or promote products
  14.       derived from this software without specific prior written permission.
  15.  
  16.    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17.    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18.    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19.    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20.    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21.    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22.    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23.    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24.    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25.    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
  26.  
  27. #ifndef __FCNTL_H
  28. #define __FCNTL_H
  29.  
  30. #ifndef __SYS_TYPES_H
  31. #include <sys/types.h>
  32. #endif
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. /* File access modes for open() and fcntl()  */
  39.  
  40. /* These fcntlbits are derived from BSD 4.4 */
  41.  
  42. #define O_RDONLY 0 /* Open for read only.  */
  43. #define O_WRONLY 1 /* Open for write only.  */
  44. #define O_RDWR 2 /* Open for read/write.  */
  45.  
  46. /* Mask for file access modes.  */
  47. #define    O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
  48.  
  49. /* Bits OR'd into the second argument to open.  */
  50.  
  51. /* Create file if it doesn't exist.  */
  52. #define O_CREAT     0x0200
  53. /* Fail if file already exists.  */
  54. #define O_EXCL        0x0800
  55. /* Truncate file to zero length.  */
  56. #define O_TRUNC            0x0400
  57. /* Send SIGIO to owner when data is ready.  */
  58. #define O_ASYNC        0x0040
  59. /* Synchronous writes.  */
  60. #define O_FSYNC        0x0080
  61. #define O_SYNC        O_FSYNC
  62. /* Open with shared file lock.  */
  63. #define O_SHLOCK    0x0010
  64. /* Open with shared exclusive lock.  */
  65. #define O_EXLOCK    0x0020
  66.  
  67. /* File status flags for open and fcntl.  */
  68.  
  69. /* Writes append to the file.  */
  70. #define O_APPEND    0x0008
  71. /* Non-blocking I/O.  */
  72. #define O_NONBLOCK      0x0004
  73. #define O_NDELAY    O_NONBLOCK
  74.  
  75. /* close on exec() flag - must be bit 8 */
  76. #define O_EXECCL    0x0100
  77.  
  78. /* Strict POSIX doesn't allow this. */
  79. #define O_BINARY    0x2000
  80. #define O_TEXT        0x1000
  81.  
  82. #define O_PIPE        0x4000 /* UnixLib specific */
  83. #define O_UNLINKED    0x8000 /* UnixLib specific - unlink file on close */
  84.  
  85.  
  86.  
  87. /* Duplicate file descriptor.  */
  88. #define F_DUPFD     0
  89. /* Return file descriptor flags.  */
  90. #define F_GETFD     1
  91. /* Set file descriptor flags.  */
  92. #define F_SETFD     2
  93. /* Read file status flags.  */
  94. #define F_GETFL     3
  95. /* Set file status flags.  */
  96. #define F_SETFL     4
  97. /* Get owner (receiver of SIGIO).  */
  98. #define F_GETOWN        5
  99. /* Set owner (receiver of SIGIO).  */
  100. #define F_SETOWN        6
  101. /* Get record locking info.  */
  102. #define F_GETLK            7
  103. /* Set record locking info (non-blocking).  */
  104. #define F_SETLK        8
  105. /* Set record locking info (blocking).  */
  106. #define F_SETLKW    9
  107. /* Get unlink on close (UnixLib internal - currently implements tmpfile). */
  108. #define F_GETUNL    10
  109. /* Set unlink on close (could be used to emulate open() then unlink trick). */
  110. #define F_SETUNL    11
  111.  
  112. /* Bits in the file status flags returned by F_GETFL.  */
  113. #define FREAD        1
  114. #define    FWRITE        2
  115.  
  116. /* Traditional BSD names the O_* bits.  */
  117. #define FASYNC        O_ASYNC
  118. #define FCREAT        O_CREAT
  119. #define FEXCL        O_EXCL
  120. #define FTRUNC        O_TRUNC
  121. #define FNOCTTY        O_NOCTTY
  122. #define FFSYNC        O_FSYNC
  123. #define FSYNC        O_SYNC
  124. #define FAPPEND        O_APPEND
  125. #define FNONBLOCK    O_NONBLOCK
  126. #define FNDELAY        O_NDELAY
  127.  
  128.  
  129. /* If set, cause the file descriptor to be closed if an exec function
  130.    is used.  Initially, set clear.  */
  131. #define FD_CLOEXEC    O_EXECCL
  132.  
  133. /* The structure describing an advisory lock.  This is the type of the third
  134.    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
  135. struct flock
  136.   {
  137.     /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
  138.     short int l_type;
  139.     /* Where `l_start' is relative to (like `lseek').  */
  140.     short int l_whence;
  141.     /* Offset where the lock begins.  */
  142.     __off_t l_start;
  143.     /* Size of the locked area; zero means until EOF.  */
  144.     __off_t l_len;
  145.     /* Process holding the lock.  */
  146.     short int l_pid;
  147.   };
  148.  
  149. /* Values for the `l_type' field of a `struct flock'.  */
  150. #define    F_RDLCK    1    /* Read lock.  */
  151. #define    F_WRLCK    2    /* Write lock.  */
  152. #define    F_UNLCK    3    /* Remove lock.  */
  153.  
  154.  
  155. #ifndef    R_OK
  156. /* Straight from <unistd.h>.  */
  157.  
  158. /* Values for the second argument to access.
  159.    These may be OR'd together.  */
  160.  
  161. /* Test for read permission.  */
  162. #define    R_OK    4
  163. /* Test for write permission.  */
  164. #define    W_OK    2
  165. /* Test for execute permission.  */
  166. #define    X_OK    1
  167. /* Test for existence.  */
  168. #define    F_OK    0
  169. #endif
  170.  
  171.  
  172. /* Do the file control operation described by CMD on FD.
  173.    The remaining arguments are interpreted depending on CMD.  */
  174. extern int fcntl (int fd, int cmd, ...);
  175.  
  176. /* Open FILE and return a new file descriptor for it, or -1 on error.
  177.    OFLAG determines the type of access used.  If O_CREAT is on OFLAG,
  178.    the third argument is taken as a `mode_t', the mode of the created file.  */
  179. extern int open (const char *file, int oflag, ...);
  180.  
  181. /* Create and open FILE, with mode MODE.
  182.    This takes an `int' MODE argument because that is
  183.    what `mode_t' will be widened to.  */
  184. extern int creat (const char *file, __mode_t mode);
  185.  
  186. #ifdef __cplusplus
  187.     }
  188. #endif
  189.  
  190. #endif
  191.