Back to index

glibc  2.9
fcntl2.h
Go to the documentation of this file.
00001 /* Checking macros for fcntl functions.
00002    Copyright (C) 2007 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 include <bits/fcntl2.h> directly; use <fcntl.h> instead."
00022 #endif
00023 
00024 /* Check that calls to open and openat with O_CREAT set have an
00025    appropriate third/fourth parameter.  */
00026 #ifndef __USE_FILE_OFFSET64
00027 extern int __open_2 (__const char *__path, int __oflag) __nonnull ((1));
00028 extern int __REDIRECT (__open_alias, (__const char *__path, int __oflag, ...),
00029                      open) __nonnull ((1));
00030 #else
00031 extern int __REDIRECT (__open_2, (__const char *__path, int __oflag),
00032                      __open64_2) __nonnull ((1));
00033 extern int __REDIRECT (__open_alias, (__const char *__path, int __oflag, ...),
00034                      open64) __nonnull ((1));
00035 #endif
00036 __errordecl (__open_too_many_args,
00037             "open can be called either with 2 or 3 arguments, not more");
00038 __errordecl (__open_missing_mode,
00039             "open with O_CREAT in second argument needs 3 arguments");
00040 
00041 __extern_always_inline int
00042 open (__const char *__path, int __oflag, ...)
00043 {
00044   if (__va_arg_pack_len () > 1)
00045     __open_too_many_args ();
00046 
00047   if (__builtin_constant_p (__oflag))
00048     {
00049       if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
00050        {
00051          __open_missing_mode ();
00052          return __open_2 (__path, __oflag);
00053        }
00054       return __open_alias (__path, __oflag, __va_arg_pack ());
00055     }
00056 
00057   if (__va_arg_pack_len () < 1)
00058     return __open_2 (__path, __oflag);
00059 
00060   return __open_alias (__path, __oflag, __va_arg_pack ());
00061 }
00062 
00063 
00064 #ifdef __USE_LARGEFILE64
00065 extern int __open64_2 (__const char *__path, int __oflag) __nonnull ((1));
00066 extern int __REDIRECT (__open64_alias, (__const char *__path, int __oflag,
00067                                    ...), open64) __nonnull ((1));
00068 __errordecl (__open64_too_many_args,
00069             "open64 can be called either with 2 or 3 arguments, not more");
00070 __errordecl (__open64_missing_mode,
00071             "open64 with O_CREAT in second argument needs 3 arguments");
00072 
00073 __extern_always_inline int
00074 open64 (__const char *__path, int __oflag, ...)
00075 {
00076   if (__va_arg_pack_len () > 1)
00077     __open64_too_many_args ();
00078 
00079   if (__builtin_constant_p (__oflag))
00080     {
00081       if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
00082        {
00083          __open64_missing_mode ();
00084          return __open64_2 (__path, __oflag);
00085        }
00086       return __open64_alias (__path, __oflag, __va_arg_pack ());
00087     }
00088 
00089   if (__va_arg_pack_len () < 1)
00090     return __open64_2 (__path, __oflag);
00091 
00092   return __open64_alias (__path, __oflag, __va_arg_pack ());
00093 }
00094 #endif
00095 
00096 
00097 #ifdef __USE_ATFILE
00098 # ifndef __USE_FILE_OFFSET64
00099 extern int __openat_2 (int __fd, __const char *__path, int __oflag)
00100      __nonnull ((2));
00101 extern int __REDIRECT (__openat_alias, (int __fd, __const char *__path,
00102                                    int __oflag, ...), openat)
00103      __nonnull ((2));
00104 # else
00105 extern int __REDIRECT (__openat_2, (int __fd, __const char *__path,
00106                                 int __oflag), __openat64_2)
00107      __nonnull ((2));
00108 extern int __REDIRECT (__openat_alias, (int __fd, __const char *__path,
00109                                    int __oflag, ...), openat64)
00110      __nonnull ((2));
00111 # endif
00112 __errordecl (__openat_too_many_args,
00113             "openat can be called either with 3 or 4 arguments, not more");
00114 __errordecl (__openat_missing_mode,
00115             "openat with O_CREAT in third argument needs 4 arguments");
00116 
00117 __extern_always_inline int
00118 openat (int __fd, __const char *__path, int __oflag, ...)
00119 {
00120   if (__va_arg_pack_len () > 1)
00121     __openat_too_many_args ();
00122 
00123   if (__builtin_constant_p (__oflag))
00124     {
00125       if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
00126        {
00127          __openat_missing_mode ();
00128          return __openat_2 (__fd, __path, __oflag);
00129        }
00130       return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
00131     }
00132 
00133   if (__va_arg_pack_len () < 1)
00134     return __openat_2 (__fd, __path, __oflag);
00135 
00136   return __openat_alias (__fd, __path, __oflag, __va_arg_pack ());
00137 }
00138 
00139 
00140 # ifdef __USE_LARGEFILE64
00141 extern int __openat64_2 (int __fd, __const char *__path, int __oflag)
00142      __nonnull ((2));
00143 extern int __REDIRECT (__openat64_alias, (int __fd, __const char *__path,
00144                                      int __oflag, ...), openat64)
00145      __nonnull ((2));
00146 __errordecl (__openat64_too_many_args,
00147             "openat64 can be called either with 3 or 4 arguments, not more");
00148 __errordecl (__openat64_missing_mode,
00149             "openat64 with O_CREAT in third argument needs 4 arguments");
00150 
00151 __extern_always_inline int
00152 openat64 (int __fd, __const char *__path, int __oflag, ...)
00153 {
00154   if (__va_arg_pack_len () > 1)
00155     __openat64_too_many_args ();
00156 
00157   if (__builtin_constant_p (__oflag))
00158     {
00159       if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
00160        {
00161          __openat64_missing_mode ();
00162          return __openat64_2 (__fd, __path, __oflag);
00163        }
00164       return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
00165     }
00166 
00167   if (__va_arg_pack_len () < 1)
00168     return __openat64_2 (__fd, __path, __oflag);
00169 
00170   return __openat64_alias (__fd, __path, __oflag, __va_arg_pack ());
00171 }
00172 # endif
00173 #endif