gonzui


Format: Advanced Search

t2ex/bsd_source/lib/libc/src_bsd/include/fcntl.hbare sourcepermlink (0.04 seconds)

Search this content:

    1: /*      $OpenBSD: fcntl.h,v 1.19 2011/07/18 17:29:49 matthew Exp $   */
    2: /*      $NetBSD: fcntl.h,v 1.8 1995/03/26 20:24:12 jtc Exp $ */
    3: 
    4: /*-
    5:  * Copyright (c) 1983, 1990, 1993
    6:  *      The Regents of the University of California.  All rights reserved.
    7:  * (c) UNIX System Laboratories, Inc.
    8:  * All or some portions of this file are derived from material licensed
    9:  * to the University of California by American Telephone and Telegraph
   10:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
   11:  * the permission of UNIX System Laboratories, Inc.
   12:  *
   13:  * Redistribution and use in source and binary forms, with or without
   14:  * modification, are permitted provided that the following conditions
   15:  * are met:
   16:  * 1. Redistributions of source code must retain the above copyright
   17:  *    notice, this list of conditions and the following disclaimer.
   18:  * 2. Redistributions in binary form must reproduce the above copyright
   19:  *    notice, this list of conditions and the following disclaimer in the
   20:  *    documentation and/or other materials provided with the distribution.
   21:  * 3. Neither the name of the University nor the names of its contributors
   22:  *    may be used to endorse or promote products derived from this software
   23:  *    without specific prior written permission.
   24:  *
   25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   35:  * SUCH DAMAGE.
   36:  *
   37:  *      @(#)fcntl.h  8.3 (Berkeley) 1/21/94
   38:  */
   39: 
   40: #ifndef _SYS_FCNTL_H_
   41: #define _SYS_FCNTL_H_
   42: 
   43: /*
   44:  * This file includes the definitions for open and fcntl
   45:  * described by POSIX for <fcntl.h>; it also includes
   46:  * related kernel definitions.
   47:  */
   48: 
   49: #include <sys/cdefs.h>
   50: #ifndef _KERNEL
   51: #include <sys/types.h>
   52: #endif
   53: 
   54: #ifdef  _T2EX
   55: 
   56: #undef _SYS_FCNTL_H_
   57: #include <../../../../include/t2ex/sys/fcntl.h>
   58: 
   59: #else   /* _T2EX */
   60: 
   61: /*
   62:  * File status flags: these are used by __libc_open(2), __libc_fcntl(2).
   63:  * They are also used (indirectly) in the kernel file structure f_flags,
   64:  * which is a superset of the open/fcntl flags.  Open flags and f_flags
   65:  * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
   66:  * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
   67:  */
   68: /* open-only flags */
   69: #define O_RDONLY        0x0000         /* open for reading only */
   70: #define O_WRONLY        0x0001         /* open for writing only */
   71: #define O_RDWR          0x0002          /* open for reading and writing */
   72: #define O_ACCMODE       0x0003                /* mask for above modes */
   73: 
   74: /*
   75:  * Kernel encoding of open mode; separate read and write bits that are
   76:  * independently testable: 1 greater than the above.
   77:  *
   78:  * XXX
   79:  * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
   80:  * which was documented to use FREAD/FWRITE, continues to work.
   81:  */
   82: #if __BSD_VISIBLE
   83: #define FREAD           0x0001
   84: #define FWRITE          0x0002
   85: #endif
   86: #define O_NONBLOCK      0x0004               /* no delay */
   87: #define O_APPEND        0x0008         /* set append mode */
   88: #if __BSD_VISIBLE
   89: #define O_SHLOCK        0x0010         /* open with shared file lock */
   90: #define O_EXLOCK        0x0020         /* open with exclusive file lock */
   91: #define O_ASYNC         0x0040         /* signal pgrp when data ready */
   92: #define O_FSYNC         0x0080         /* backwards compatibility */
   93: #define O_NOFOLLOW      0x0100               /* if path is a symlink, don't follow */
   94: #endif
   95: #if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 420
   96: #define O_SYNC          0x0080          /* synchronous writes */
   97: #endif
   98: #define O_CREAT         0x0200         /* create if nonexistent */
   99: #define O_TRUNC         0x0400         /* truncate to zero length */
  100: #define O_EXCL          0x0800          /* error if already exists */
  101: 
  102: /* XXX - FHASLOCK should be FIF_HASLOCK. */
  103: #ifdef _KERNEL
  104: #define FHASLOCK        0x4000         /* descriptor holds advisory lock */
  105: #endif
  106: 
  107: /*
  108:  * POSIX 1003.1 specifies a higher granularity for synchronous operations
  109:  * than we support.  Since synchronicity is all or nothing in OpenBSD
  110:  * we just define these to be the same as O_SYNC.
  111:  */
  112: #define O_DSYNC         O_SYNC         /* synchronous data writes */
  113: #define O_RSYNC         O_SYNC         /* synchronous reads */
  114: 
  115: /* defined by POSIX 1003.1; BSD default, this bit is not required */
  116: #define O_NOCTTY        0x8000         /* don't assign controlling terminal */
  117: 
  118: /* defined by POSIX Issue 7 */
  119: #define O_CLOEXEC       0x10000               /* atomically set FD_CLOEXEC */
  120: #define O_DIRECTORY     0x20000             /* fail if not a directory */
  121: 
  122: #ifdef _KERNEL
  123: /*
  124:  * convert from __libc_open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE.
  125:  * For out-of-range values for the flags, be slightly careful (but lossy).
  126:  */
  127: #define FFLAGS(oflags)  (((oflags) & ~O_ACCMODE) | (((oflags) + 1) & O_ACCMODE))
  128: #define OFLAGS(fflags)  (((fflags) & ~O_ACCMODE) | (((fflags) - 1) & O_ACCMODE))
  129: 
  130: /* bits to save after open */
  131: #define FMASK           (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
  132: /* bits settable by __libc_fcntl(F_SETFL, ...) */
  133: #define FCNTLFLAGS      (FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
  134: #endif
  135: 
  136: /*
  137:  * The O_* flags used to have only F* names, which were used in the kernel
  138:  * and by fcntl.  We retain the F* names for the kernel f_flags field
  139:  * and for backward compatibility for fcntl.
  140:  */
  141: #if __BSD_VISIBLE
  142: #define FAPPEND         O_APPEND       /* kernel/compat */
  143: #define FASYNC          O_ASYNC         /* kernel/compat */
  144: #define FFSYNC          O_SYNC          /* kernel */
  145: #define FNONBLOCK       O_NONBLOCK    /* kernel */
  146: #define FNDELAY         O_NONBLOCK     /* compat */
  147: #define O_NDELAY        O_NONBLOCK     /* compat */
  148: #endif
  149: 
  150: /*
  151:  * Constants used for __libc_fcntl(2)
  152:  */
  153: 
  154: /* command values */
  155: #define F_DUPFD         0              /* duplicate file descriptor */
  156: #define F_GETFD         1              /* get file descriptor flags */
  157: #define F_SETFD         2              /* set file descriptor flags */
  158: #define F_GETFL         3              /* get file status flags */
  159: #define F_SETFL         4              /* set file status flags */
  160: #if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 500
  161: #define F_GETOWN        5              /* get SIGIO/SIGURG proc/pgrp */
  162: #define F_SETOWN        6              /* set SIGIO/SIGURG proc/pgrp */
  163: #endif
  164: #define F_GETLK         7              /* get record locking information */
  165: #define F_SETLK         8              /* set record locking information */
  166: #define F_SETLKW        9              /* F_SETLK; wait if blocked */
  167: #if __POSIX_VISIBLE >= 200809
  168: #define F_DUPFD_CLOEXEC 10              /* duplicate with FD_CLOEXEC set */
  169: #endif
  170: 
  171: /* file descriptor flags (F_GETFD, F_SETFD) */
  172: #define FD_CLOEXEC      1            /* close-on-exec flag */
  173: 
  174: /* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
  175: #define F_RDLCK         1              /* shared or read lock */
  176: #define F_UNLCK         2              /* unlock */
  177: #define F_WRLCK         3              /* exclusive or write lock */
  178: #ifdef _KERNEL
  179: #define F_WAIT          0x010           /* Wait until lock is granted */
  180: #define F_FLOCK         0x020           /* Use flock(2) semantics for lock */
  181: #define F_POSIX         0x040           /* Use POSIX semantics for lock */
  182: #endif
  183: 
  184: /*
  185:  * Advisory file segment locking data type -
  186:  * information passed to system by user
  187:  */
  188: struct flock {
  189:         off_t  l_start; /* starting offset */
  190:         off_t  l_len;           /* len = 0 means until end of file */
  191:         pid_t  l_pid;           /* lock owner */
  192:         short  l_type;          /* lock type: read/write, etc. */
  193:         short  l_whence;        /* type of l_start */
  194: };
  195: 
  196: #if __BSD_VISIBLE
  197: /* lock operations for flock(2) */
  198: #define LOCK_SH         0x01           /* shared file lock */
  199: #define LOCK_EX         0x02           /* exclusive file lock */
  200: #define LOCK_NB         0x04           /* don't block when locking */
  201: #define LOCK_UN         0x08           /* unlock file */
  202: #endif
  203: 
  204: #if __POSIX_VISIBLE >= 200809
  205: #define AT_FDCWD        -100
  206: 
  207: #define AT_EACCESS              0x01
  208: #define AT_SYMLINK_NOFOLLOW     0x02
  209: #define AT_SYMLINK_FOLLOW       0x04
  210: #define AT_REMOVEDIR            0x08
  211: #endif
  212: 
  213: #endif  /* _T2EX */
  214: 
  215: #ifndef _KERNEL
  216: __BEGIN_DECLS
  217: #ifdef  _T2EX
  218: int     fs_open(const char *path, int oflag, ... /* mode_t mode */ );
  219: int     fs_fcntl(int fd, int cmd, ... /* arg */ );
  220: #define __libc_open     fs_open
  221: #define __libc_fcntl    fs_fcntl
  222: #else   /* _T2EX */
  223: int     __libc_open(const char *, int, ...);
  224: int     __libc_fcntl(int, int, ...);
  225: #endif  /* _T2EX */
  226: int     creat(const char *, mode_t);
  227: 
  228: #if __BSD_VISIBLE
  229: int     flock(int, int);
  230: #endif
  231: #if __POSIX_VISIBLE >= 200809
  232: int     openat(int, const char *, int, ...);
  233: #endif
  234: __END_DECLS
  235: #endif
  236: 
  237: #endif /* !_SYS_FCNTL_H_ */
  238: