Back to index

glibc  2.9
fcntl.h
Go to the documentation of this file.
00001 /* O_*, F_*, FD_* bit values for 4.3 BSD.
00002    Copyright (C) 1991, 1992, 1997, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef       _FCNTL_H
00021 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
00022 #endif
00023 
00024 
00025 /* File access modes for `open' and `fcntl'.  */
00026 #define       O_RDONLY      0      /* Open read-only.  */
00027 #define       O_WRONLY      1      /* Open write-only.  */
00028 #define       O_RDWR        2      /* Open read/write.  */
00029 
00030 
00031 /* Bits OR'd into the second argument to open.  */
00032 #define       O_CREAT              0x0200 /* Create file if it doesn't exist.  */
00033 #define       O_EXCL        0x0800 /* Fail if file already exists.  */
00034 #define       O_TRUNC              0x0400 /* Truncate file to zero length.  */
00035 /* Apparently not assigning a controlling terminal is the default
00036    behavior in BSD, so no bit is required to request that behavior.  */
00037 #define       O_NOCTTY      0      /* Don't assign a controlling terminal.  */
00038 #if defined __USE_BSD || defined __USE_SVID
00039 # define O_ASYNC            0x0040 /* Send SIGIO to owner when data is ready.  */
00040 # define O_FSYNC            0x2000 /* Synchronous writes.  */
00041 # define O_SYNC             O_FSYNC
00042 #endif
00043 
00044 /* File status flags for `open' and `fcntl'.  */
00045 #define       O_APPEND      0x0008 /* Writes append to the file.  */
00046 #define       O_NONBLOCK    0x0004 /* Non-blocking I/O.  */
00047 
00048 #ifdef __USE_BSD
00049 /* BSD before 4.4 doesn't support POSIX.1 O_NONBLOCK,
00050    but O_NDELAY is close.  */
00051 # define O_NDELAY    O_NONBLOCK
00052 #endif
00053 
00054 #ifdef __USE_BSD
00055 /* Bits in the file status flags returned by F_GETFL.
00056    These are all the O_* flags, plus FREAD and FWRITE, which are
00057    independent bits set by which of O_RDONLY, O_WRONLY, and O_RDWR, was
00058    given to `open'.  */
00059 # define FREAD              1
00060 # define FWRITE             2
00061 
00062 /* Traditional BSD names the O_* bits.  */
00063 # define FASYNC             O_ASYNC
00064 # define FCREAT             O_CREAT
00065 # define FEXCL              O_EXCL
00066 # define FTRUNC             O_TRUNC
00067 # define FNOCTTY     O_NOCTTY
00068 # define FFSYNC             O_FSYNC
00069 # define FSYNC              O_SYNC
00070 # define FAPPEND     O_APPEND
00071 # define FNONBLOCK   O_NONBLOCK
00072 # define FNDELAY     O_NDELAY
00073 #endif
00074 
00075 /* Mask for file access modes.  This is system-dependent in case
00076    some system ever wants to define some other flavor of access.  */
00077 #define       O_ACCMODE     (O_RDONLY|O_WRONLY|O_RDWR)
00078 
00079 /* XXX missing */
00080 #define O_LARGEFILE  0
00081 
00082 /* Values for the second argument to `fcntl'.  */
00083 #define       F_DUPFD              0      /* Duplicate file descriptor.  */
00084 #define       F_GETFD              1      /* Get file descriptor flags.  */
00085 #define       F_SETFD              2      /* Set file descriptor flags.  */
00086 #define       F_GETFL              3      /* Get file status flags.  */
00087 #define       F_SETFL              4      /* Set file status flags.  */
00088 #if defined __USE_BSD || defined __USE_UNIX98
00089 # define F_GETOWN    5      /* Get owner (receiver of SIGIO).  */
00090 # define F_SETOWN    6      /* Set owner (receiver of SIGIO).  */
00091 #endif
00092 #define       F_GETLK              7      /* Get record locking info.  */
00093 #define       F_SETLK              8      /* Set record locking info (non-blocking).  */
00094 #define       F_SETLKW      9      /* Set record locking info (blocking).  */
00095 
00096 /* XXX missing */
00097 #define F_GETLK64    7      /* Get record locking info.  */
00098 #define F_SETLK64    8      /* Set record locking info (non-blocking).  */
00099 #define F_SETLKW64   9      /* Set record locking info (blocking).  */
00100 
00101 /* File descriptor flags used with F_GETFD and F_SETFD.  */
00102 #define       FD_CLOEXEC    1      /* Close on exec.  */
00103 
00104 
00105 #include <bits/types.h>
00106 
00107 /* The structure describing an advisory lock.  This is the type of the third
00108    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
00109 struct flock
00110   {
00111     short int l_type;       /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
00112     short int l_whence;     /* Where `l_start' is relative to (like `lseek').  */
00113 #ifndef __USE_FILE_OFFSET64
00114     __off_t l_start; /* Offset where the lock begins.  */
00115     __off_t l_len;   /* Size of the locked area; zero means until EOF.  */
00116 #else
00117     __off64_t l_start;      /* Offset where the lock begins.  */
00118     __off64_t l_len; /* Size of the locked area; zero means until EOF.  */
00119 #endif
00120     short int l_pid; /* Process holding the lock.  */
00121     short int l_xxx; /* Reserved for future use.  */
00122   };
00123 
00124 #ifdef __USE_LARGEFILE64
00125 struct flock64
00126   {
00127     short int l_type;       /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
00128     short int l_whence;     /* Where `l_start' is relative to (like `lseek').  */
00129     __off64_t l_start;      /* Offset where the lock begins.  */
00130     __off64_t l_len; /* Size of the locked area; zero means until EOF.  */
00131     short int l_pid; /* Process holding the lock.  */
00132     short int l_xxx; /* Reserved for future use.  */
00133   };
00134 #endif
00135 
00136 /* Values for the `l_type' field of a `struct flock'.  */
00137 #define       F_RDLCK       1      /* Read lock.  */
00138 #define       F_WRLCK       2      /* Write lock.  */
00139 #define       F_UNLCK       3      /* Remove lock.  */