home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / usr / include / fcntl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-13  |  6.4 KB  |  183 lines  |  [TEXT/R*ch]

  1. /*-
  2.  * Copyright (c) 1983, 1990 The Regents of the University of California.
  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. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    from: @(#)fcntl.h    5.14 (Berkeley) 7/1/91
  34.  *    $Id: fcntl.h,v 1.3 1993/05/20 16:22:12 cgd Exp $
  35.  */
  36.  
  37. #ifndef _SYS_FCNTL_H_
  38. #define    _SYS_FCNTL_H_
  39.  
  40. /*
  41.  * This file includes the definitions for open and fcntl
  42.  * described by POSIX for <fcntl.h>; it also includes
  43.  * related kernel definitions.
  44.  */
  45.  
  46. #ifndef KERNEL
  47. #include <sys/types.h>
  48. #endif
  49.  
  50. /*
  51.  * File status flags: these are used by open(2), fcntl(2).
  52.  * They are also used (indirectly) in the kernel file structure f_flags,
  53.  * which is a superset of the open/fcntl flags.  Open flags and f_flags
  54.  * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
  55.  * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
  56.  */
  57. /* open-only flags */
  58. #define    O_RDONLY    0x0000        /* open for reading only */
  59. #define    O_WRONLY    0x0001        /* open for writing only */
  60. #define    O_RDWR        0x0002        /* open for reading and writing */
  61. #define    O_ACCMODE    0x0003        /* mask for above modes */
  62.  
  63. #ifdef KERNEL
  64. /*
  65.  * Kernel encoding of open mode; separate read and write bits
  66.  * that are independently testable: 1 greater than the above.
  67.  */
  68. #define    FREAD        0x0001
  69. #define    FWRITE        0x0002
  70. #endif
  71. #define    O_NONBLOCK    0x0004        /* no delay */
  72. #define    O_APPEND    0x0008        /* set append mode */
  73. #ifndef _POSIX_SOURCE
  74. #define    O_SHLOCK    0x0010        /* open with shared file lock */
  75. #define    O_EXLOCK    0x0020        /* open with exclusive file lock */
  76. #define    O_ASYNC        0x0040        /* signal pgrp when data ready */
  77. #define    O_FSYNC        0x0080        /* synchronous writes */
  78. #endif
  79. #define    O_CREAT        0x0200        /* create if nonexistant */
  80. #define    O_TRUNC        0x0400        /* truncate to zero length */
  81. #define    O_EXCL        0x0800        /* error if already exists */
  82. #ifdef KERNEL
  83. #define    FMARK        0x1000        /* mark during gc() */
  84. #define    FDEFER        0x2000        /* defer for next gc pass */
  85. #define    FHASLOCK    0x4000        /* descriptor holds advisory lock */
  86. #endif
  87.  
  88. /* defined by POSIX 1003.1; BSD default, so no bit required */
  89. #define    O_NOCTTY    0        /* don't assign controlling terminal */
  90.  
  91. #ifdef KERNEL
  92. /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
  93. #define    FFLAGS(oflags)    ((oflags) + 1)
  94. #define    OFLAGS(fflags)    ((fflags) - 1)
  95.  
  96. /* bits to save after open */
  97. #define    FMASK        (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
  98. /* bits settable by fcntl(F_SETFL, ...) */
  99. #define    FCNTLFLAGS    (FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
  100. #endif
  101.  
  102. /*
  103.  * The O_* flags used to have only F* names, which were used in the kernel
  104.  * and by fcntl.  We retain the F* names for the kernel f_flags field
  105.  * and for backward compatibility for fcntl.
  106.  */
  107. #ifndef _POSIX_SOURCE
  108. #define    FAPPEND        O_APPEND    /* kernel/compat */
  109. #define    FASYNC        O_ASYNC        /* kernel/compat */
  110. #define    FFSYNC        O_FSYNC        /* kernel */
  111. #define    FNONBLOCK    O_NONBLOCK    /* kernel */
  112. #define    FNDELAY        O_NONBLOCK    /* compat */
  113. #define    O_NDELAY    O_NONBLOCK    /* compat */
  114. #endif
  115.  
  116. /*
  117.  * Constants used for fcntl(2)
  118.  */
  119.  
  120. /* command values */
  121. #define    F_DUPFD        0        /* duplicate file descriptor */
  122. #define    F_GETFD        1        /* get file descriptor flags */
  123. #define    F_SETFD        2        /* set file descriptor flags */
  124. #define    F_GETFL        3        /* get file status flags */
  125. #define    F_SETFL        4        /* set file status flags */
  126. #ifndef _POSIX_SOURCE
  127. #define    F_GETOWN    5        /* get SIGIO/SIGURG proc/pgrp */
  128. #define F_SETOWN    6        /* set SIGIO/SIGURG proc/pgrp */
  129. #endif
  130. #define    F_GETLK        7        /* get record locking information */
  131. #define    F_SETLK        8        /* set record locking information */
  132. #define    F_SETLKW    9        /* F_SETLK; wait if blocked */
  133.  
  134. /* file descriptor flags (F_GETFD, F_SETFD) */
  135. #define    FD_CLOEXEC    1        /* close-on-exec flag */
  136.  
  137. /* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
  138. #define    F_RDLCK        1        /* shared or read lock */
  139. #define    F_UNLCK        2        /* unlock */
  140. #define    F_WRLCK        3        /* exclusive or write lock */
  141. #ifdef KERNEL
  142. #define    F_WAIT        0x010        /* Wait until lock is granted */
  143. #define    F_FLOCK        0x020         /* Use flock(2) semantics for lock */
  144. #define    F_POSIX        0x040         /* Use POSIX semantics for lock */
  145. #endif
  146.  
  147. /*
  148.  * Advisory file segment locking data type -
  149.  * information passed to system by user
  150.  */
  151. struct flock {
  152.     short    l_type;        /* lock type: read/write, etc. */
  153.     short    l_whence;    /* type of l_start */
  154.     off_t    l_start;    /* starting offset */
  155.     off_t    l_len;        /* len = 0 means until end of file */
  156.     pid_t    l_pid;        /* lock owner */
  157. };
  158.  
  159.  
  160. #ifndef _POSIX_SOURCE
  161. /* lock operations for flock(2) */
  162. #define    LOCK_SH        0x01        /* shared file lock */
  163. #define    LOCK_EX        0x02        /* exclusive file lock */
  164. #define    LOCK_NB        0x04        /* don't block when locking */
  165. #define    LOCK_UN        0x08        /* unlock file */
  166. #endif
  167.  
  168.  
  169. #ifndef KERNEL
  170. #include <sys/cdefs.h>
  171.  
  172. __BEGIN_DECLS
  173. int    open __P((const char *, int, ...));
  174. int    creat __P((const char *, mode_t));
  175. int    fcntl __P((int, int, ...));
  176. #ifndef _POSIX_SOURCE
  177. int    flock __P((int, int));
  178. #endif /* !_POSIX_SOURCE */
  179. __END_DECLS
  180. #endif
  181.  
  182. #endif /* !_SYS_FCNTL_H_ */
  183.