Back to index

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