Back to index

glibc  2.9
fcntl.h
Go to the documentation of this file.
00001 /* O_*, F_*, FD_* bit values for System V.
00002    Copyright (C) 1991, 1992, 1997 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              00400  /* Create file if it doesn't exist.  */
00033 #define       O_EXCL        02000  /* Fail if file already exists.  */
00034 #define       O_TRUNC              01000  /* Truncate file to zero length.  */
00035 #if defined __USE_BSD || defined __USE_SVID
00036 #define       O_SYNC        00020  /* Synchronous writes.  */
00037 #define       O_FSYNC              O_SYNC
00038 #endif
00039 
00040 /* File status flags for `open' and `fcntl'.  */
00041 #define       O_APPEND      000010 /* Writes append to the file.  */
00042 #define       O_NONBLOCK    000004 /* Non-blocking I/O.  */
00043 
00044 #ifdef __USE_BSD
00045 /* System V doesn't support POSIX.1 O_NONBLOCK, but O_NDELAY is close.  */
00046 #define       O_NDELAY      O_NONBLOCK
00047 #endif
00048 
00049 /* Mask for file access modes.  This is system-dependent in case
00050    some system ever wants to define some other flavor of access.  */
00051 #define       O_ACCMODE     (O_RDONLY|O_WRONLY|O_RDWR)
00052 
00053 /* Values for the second argument to `fcntl'.  */
00054 #define       F_DUPFD              0      /* Duplicate file descriptor.  */
00055 #define       F_GETFD              1      /* Get file descriptor flags.  */
00056 #define       F_SETFD              2      /* Set file descriptor flags.  */
00057 #define       F_GETFL              3      /* Get file status flags.  */
00058 #define       F_SETFL              4      /* Set file status flags.  */
00059 #define       F_GETLK              5      /* Get record locking info.  */
00060 #define       F_SETLK              6      /* Set record locking info.  */
00061 #define       F_SETLKW      7      /* Set record locking info, wait.  */
00062 
00063 /* File descriptor flags used with F_GETFD and F_SETFD.  */
00064 #define       FD_CLOEXEC    1      /* Close on exec.  */
00065 
00066 
00067 #include <bits/types.h>
00068 
00069 /* The structure describing an advisory lock.  This is the type of the third
00070    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
00071 struct flock
00072   {
00073     short int l_type;       /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
00074     short int l_whence;     /* Where `l_start' is relative to (like `lseek').  */
00075     __off_t l_start; /* Offset where the lock begins.  */
00076     __off_t l_len;   /* Size of the locked area; zero means until EOF.  */
00077     short int l_sysid;      /* System ID where locking process resides. */
00078     short int l_pid; /* Process holding the lock.  */
00079   };
00080 
00081 /* Values for the `l_type' field of a `struct flock'.  */
00082 #define       F_RDLCK       1      /* Read lock.  */
00083 #define       F_WRLCK       2      /* Write lock.  */
00084 #define       F_UNLCK       3      /* Remove lock.  */
00085 
00086 
00087 /* Define some more compatibility macros to be backward compatible with
00088    BSD systems which did not managed to hide these kernel macros.  */
00089 #ifdef __USE_BSD
00090 #define       FAPPEND              O_APPEND
00091 #define       FFSYNC        O_FSYNC
00092 #define       FNONBLOCK     O_NONBLOCK
00093 #define       FNDELAY              O_NDELAY
00094 #endif /* Use BSD.  */