Back to index

glibc  2.9
fcntl.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991,1992,1994-2001,2003,2004,2005,2006,2007
00002        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 /*
00021  *     POSIX Standard: 6.5 File Control Operations      <fcntl.h>
00022  */
00023 
00024 #ifndef       _FCNTL_H
00025 #define       _FCNTL_H      1
00026 
00027 #include <features.h>
00028 
00029 /* This must be early so <bits/fcntl.h> can define types winningly.  */
00030 __BEGIN_DECLS
00031 
00032 /* Get the definitions of O_*, F_*, FD_*: all the
00033    numbers and flag bits for `open', `fcntl', et al.  */
00034 #include <bits/fcntl.h>
00035 
00036 /* For XPG all symbols from <sys/stat.h> should also be available.  */
00037 #ifdef __USE_XOPEN
00038 # include <sys/stat.h>
00039 #endif
00040 
00041 #ifdef __USE_MISC
00042 # ifndef R_OK               /* Verbatim from <unistd.h>.  Ugh.  */
00043 /* Values for the second argument to access.
00044    These may be OR'd together.  */
00045 #  define R_OK       4             /* Test for read permission.  */
00046 #  define W_OK       2             /* Test for write permission.  */
00047 #  define X_OK       1             /* Test for execute permission.  */
00048 #  define F_OK       0             /* Test for existence.  */
00049 # endif
00050 #endif /* Use misc.  */
00051 
00052 /* XPG wants the following symbols.  */
00053 #ifdef __USE_XOPEN          /* <stdio.h> has the same definitions.  */
00054 # define SEEK_SET    0      /* Seek from beginning of file.  */
00055 # define SEEK_CUR    1      /* Seek from current position.  */
00056 # define SEEK_END    2      /* Seek from end of file.  */
00057 #endif /* XPG */
00058 
00059 #ifdef __USE_ATFILE
00060 # define AT_FDCWD           -100   /* Special value used to indicate
00061                                       the *at functions should use the
00062                                       current working directory. */
00063 # define AT_SYMLINK_NOFOLLOW       0x100  /* Do not follow symbolic links.  */
00064 # define AT_REMOVEDIR              0x200  /* Remove directory instead of
00065                                       unlinking file.  */
00066 # define AT_SYMLINK_FOLLOW  0x400  /* Follow symbolic links.  */
00067 # define AT_EACCESS         0x200  /* Test access permitted for
00068                                       effective IDs, not real IDs.  */
00069 #endif
00070 
00071 /* Do the file control operation described by CMD on FD.
00072    The remaining arguments are interpreted depending on CMD.
00073 
00074    This function is a cancellation point and therefore not marked with
00075    __THROW.  */
00076 extern int fcntl (int __fd, int __cmd, ...);
00077 
00078 /* Open FILE and return a new file descriptor for it, or -1 on error.
00079    OFLAG determines the type of access used.  If O_CREAT is on OFLAG,
00080    the third argument is taken as a `mode_t', the mode of the created file.
00081 
00082    This function is a cancellation point and therefore not marked with
00083    __THROW.  */
00084 #ifndef __USE_FILE_OFFSET64
00085 extern int open (__const char *__file, int __oflag, ...) __nonnull ((1));
00086 #else
00087 # ifdef __REDIRECT
00088 extern int __REDIRECT (open, (__const char *__file, int __oflag, ...), open64)
00089      __nonnull ((1));
00090 # else
00091 #  define open open64
00092 # endif
00093 #endif
00094 #ifdef __USE_LARGEFILE64
00095 extern int open64 (__const char *__file, int __oflag, ...) __nonnull ((1));
00096 #endif
00097 
00098 #ifdef __USE_ATFILE
00099 /* Similar to `open' but a relative path name is interpreted relative to
00100    the directory for which FD is a descriptor.
00101 
00102    NOTE: some other `openat' implementation support additional functionality
00103    through this interface, especially using the O_XATTR flag.  This is not
00104    yet supported here.
00105 
00106    This function is a cancellation point and therefore not marked with
00107    __THROW.  */
00108 # ifndef __USE_FILE_OFFSET64
00109 extern int openat (int __fd, __const char *__file, int __oflag, ...)
00110      __nonnull ((2));
00111 # else
00112 #  ifdef __REDIRECT
00113 extern int __REDIRECT (openat, (int __fd, __const char *__file, int __oflag,
00114                             ...), openat64) __nonnull ((2));
00115 #  else
00116 #   define openat openat64
00117 #  endif
00118 # endif
00119 
00120 extern int openat64 (int __fd, __const char *__file, int __oflag, ...)
00121      __nonnull ((2));
00122 #endif
00123 
00124 /* Create and open FILE, with mode MODE.  This takes an `int' MODE
00125    argument because that is what `mode_t' will be widened to.
00126 
00127    This function is a cancellation point and therefore not marked with
00128    __THROW.  */
00129 #ifndef __USE_FILE_OFFSET64
00130 extern int creat (__const char *__file, __mode_t __mode) __nonnull ((1));
00131 #else
00132 # ifdef __REDIRECT
00133 extern int __REDIRECT (creat, (__const char *__file, __mode_t __mode),
00134                      creat64) __nonnull ((1));
00135 # else
00136 #  define creat creat64
00137 # endif
00138 #endif
00139 #ifdef __USE_LARGEFILE64
00140 extern int creat64 (__const char *__file, __mode_t __mode) __nonnull ((1));
00141 #endif
00142 
00143 #if !defined F_LOCK && (defined __USE_MISC || (defined __USE_XOPEN_EXTENDED \
00144                                           && !defined __USE_POSIX))
00145 /* NOTE: These declarations also appear in <unistd.h>; be sure to keep both
00146    files consistent.  Some systems have them there and some here, and some
00147    software depends on the macros being defined without including both.  */
00148 
00149 /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
00150    LEN is always relative to the current file position.
00151    The CMD argument is one of the following.  */
00152 
00153 # define F_ULOCK 0   /* Unlock a previously locked region.  */
00154 # define F_LOCK  1   /* Lock a region for exclusive use.  */
00155 # define F_TLOCK 2   /* Test and lock a region for exclusive use.  */
00156 # define F_TEST  3   /* Test a region for other processes locks.  */
00157 
00158 # ifndef __USE_FILE_OFFSET64
00159 extern int lockf (int __fd, int __cmd, __off_t __len);
00160 # else
00161 # ifdef __REDIRECT
00162 extern int __REDIRECT (lockf, (int __fd, int __cmd, __off64_t __len), lockf64);
00163 # else
00164 #  define lockf lockf64
00165 # endif
00166 # endif
00167 # ifdef __USE_LARGEFILE64
00168 extern int lockf64 (int __fd, int __cmd, __off64_t __len);
00169 # endif
00170 #endif
00171 
00172 #ifdef __USE_XOPEN2K
00173 /* Advice the system about the expected behaviour of the application with
00174    respect to the file associated with FD.  */
00175 # ifndef __USE_FILE_OFFSET64
00176 extern int posix_fadvise (int __fd, __off_t __offset, __off_t __len,
00177                        int __advise) __THROW;
00178 # else
00179 # ifdef __REDIRECT_NTH
00180 extern int __REDIRECT_NTH (posix_fadvise, (int __fd, __off64_t __offset,
00181                                       __off64_t __len, int __advise),
00182                         posix_fadvise64);
00183 # else
00184 #  define posix_fadvise posix_fadvise64
00185 # endif
00186 # endif
00187 # ifdef __USE_LARGEFILE64
00188 extern int posix_fadvise64 (int __fd, __off64_t __offset, __off64_t __len,
00189                          int __advise) __THROW;
00190 # endif
00191 
00192 
00193 /* Reserve storage for the data of the file associated with FD.
00194 
00195    This function is a possible cancellation points and therefore not
00196    marked with __THROW.  */
00197 # ifndef __USE_FILE_OFFSET64
00198 extern int posix_fallocate (int __fd, __off_t __offset, __off_t __len);
00199 # else
00200 # ifdef __REDIRECT
00201 extern int __REDIRECT (posix_fallocate, (int __fd, __off64_t __offset,
00202                                     __off64_t __len),
00203                      posix_fallocate64);
00204 # else
00205 #  define posix_fallocate posix_fallocate64
00206 # endif
00207 # endif
00208 # ifdef __USE_LARGEFILE64
00209 extern int posix_fallocate64 (int __fd, __off64_t __offset, __off64_t __len);
00210 # endif
00211 #endif
00212 
00213 
00214 /* Define some inlines helping to catch common problems.  */
00215 #if __USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline \
00216     && defined __va_arg_pack_len
00217 # include <bits/fcntl2.h>
00218 #endif
00219 
00220 __END_DECLS
00221 
00222 #endif /* fcntl.h  */