Back to index

glibc  2.9
fcntl.h
Go to the documentation of this file.
00001 /* O_*, F_*, FD_* bit values for Linux.
00002    Copyright (C) 1995-1999, 2000, 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 #include <sys/types.h>
00026 
00027 /* open/fcntl.  */
00028 #define O_ACCMODE      0003
00029 #define O_RDONLY         00
00030 #define O_WRONLY         01
00031 #define O_RDWR                  02
00032 #define O_NONBLOCK       04
00033 #define O_NDELAY    O_NONBLOCK
00034 #define O_APPEND        010
00035 #define O_SYNC                 020
00036 #define O_FSYNC             O_SYNC
00037 #define O_CREAT               0400 /* not fcntl */
00038 #define O_TRUNC              01000 /* not fcntl */
00039 #define O_EXCL               02000 /* not fcntl */
00040 #define O_NOCTTY      04000 /* not fcntl */
00041 #define O_ASYNC             0400000
00042 
00043 #ifdef __USE_LARGEFILE64
00044 # define O_LARGEFILE 0400000000
00045 #endif
00046 
00047 /* For now Linux has synchronisity options for data and read operations.
00048    We define the symbols here but let them do the same as O_SYNC since
00049    this is a superset.  */
00050 #if defined __USE_POSIX199309 || defined __USE_UNIX98
00051 # define O_DSYNC     020000000     /* Synchronize data.  */
00052 # define O_RSYNC     010000000     /* Synchronize read operations.  */
00053 #endif
00054 
00055 /* Values for the second argument to `fcntl'.  */
00056 #define F_DUPFD             0      /* Duplicate file descriptor.  */
00057 #define F_GETFD             1      /* Get file descriptor flags.  */
00058 #define F_SETFD             2      /* Set file descriptor flags.  */
00059 #define F_GETFL             3      /* Get file status flags.  */
00060 #define F_SETFL             4      /* Set file status flags.  */
00061 #ifndef __USE_FILE_OFFSET64
00062 # define F_GETLK     5      /* Get record locking info.  */
00063 # define F_SETLK     6      /* Set record locking info (non-blocking).  */
00064 # define F_SETLKW    7      /* Set record locking info (blocking).  */
00065 #else
00066 # define F_GETLK       11   /* Get record locking info.  */
00067 # define F_SETLK       12   /* Set record locking info (non-blocking).  */
00068 # define F_SETLKW      13   /* Set record locking info (blocking).  */
00069 #endif
00070 
00071 #ifdef __USE_LARGEFILE64
00072 # define F_GETLK64      11  /* Get record locking info.  */
00073 # define F_SETLK64      12  /* Set record locking info (non-blocking).  */
00074 # define F_SETLKW64     13  /* Set record locking info (blocking).  */
00075 #endif
00076 
00077 #if defined __USE_BSD || defined __USE_UNIX98
00078 # define F_SETOWN    8      /* Get owner of socket (receiver of SIGIO).  */
00079 # define F_GETOWN    9      /* Set owner of socket (receiver of SIGIO).  */
00080 #endif
00081 
00082 /* For F_[GET|SET]FD.  */
00083 #define FD_CLOEXEC   1      /* actually anything with low bit set goes */
00084 
00085 /* For posix fcntl() and `l_type' field of a `struct flock' for lockf().  */
00086 #define F_RDLCK             1      /* Read lock.  */
00087 #define F_WRLCK             2      /* Write lock.  */
00088 #define F_UNLCK             3      /* Remove lock.  */
00089 
00090 #ifdef __USE_BSD
00091 /* Operations for bsd flock(), also used by the kernel implementation */
00092 # define LOCK_SH     1      /* shared lock */
00093 # define LOCK_EX     2      /* exclusive lock */
00094 # define LOCK_NB     4      /* or'd with one of the above to prevent
00095                                blocking */
00096 # define LOCK_UN     8      /* remove lock */
00097 #endif
00098 
00099 struct flock
00100   {
00101     short int l_type;       /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
00102     short int l_whence;     /* Where `l_start' is relative to (like `lseek').  */
00103 #ifndef __USE_FILE_OFFSET64
00104     __off_t l_start; /* Offset where the lock begins.  */
00105     __off_t l_len;   /* Size of the locked area; zero means until EOF.  */
00106 #endif
00107     unsigned int l_sysid;
00108     __pid_t l_pid;   /* Process holding the lock.  */
00109     int l_vfs;
00110 #ifdef __USE_FILE_OFFSET64
00111     __off64_t l_start;      /* Offset where the lock begins.  */
00112     __off64_t l_len; /* Size of the locked area; zero means until EOF.  */
00113 #endif
00114   };
00115 
00116 #ifdef __USE_LARGEFILE64
00117 struct flock64
00118   {
00119     short int l_type;       /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
00120     short int l_whence;     /* Where `l_start' is relative to (like `lseek').  */
00121     unsigned int l_sysid;
00122     __pid_t l_pid;   /* Process holding the lock.  */
00123     int l_vfs;
00124     __off64_t l_start;      /* Offset where the lock begins.  */
00125     __off64_t l_len; /* Size of the locked area; zero means until EOF.  */
00126   };
00127 #endif
00128 
00129 /* Define some more compatibility macros to be backward compatible with
00130    BSD systems which did not managed to hide these kernel macros.  */
00131 #ifdef __USE_BSD
00132 # define FAPPEND     O_APPEND
00133 # define FFSYNC             O_FSYNC
00134 # define FASYNC             O_ASYNC
00135 # define FNONBLOCK   O_NONBLOCK
00136 # define FNDELAY     O_NDELAY
00137 #endif /* Use BSD.  */