Back to index

glibc  2.9
unistd.h
Go to the documentation of this file.
00001 /* Checking macros for unistd functions.
00002    Copyright (C) 2005, 2006, 2007, 2008 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 _UNISTD_H
00021 # error "Never include <bits/unistd.h> directly; use <unistd.h> instead."
00022 #endif
00023 
00024 extern ssize_t __read_chk (int __fd, void *__buf, size_t __nbytes,
00025                         size_t __buflen) __wur;
00026 extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
00027                                      size_t __nbytes), read) __wur;
00028 extern ssize_t __REDIRECT (__read_chk_warn,
00029                         (int __fd, void *__buf, size_t __nbytes,
00030                          size_t __buflen), __read_chk)
00031      __wur __warnattr ("read called with bigger length than size of "
00032                      "the destination buffer");
00033 
00034 __extern_always_inline __wur ssize_t
00035 read (int __fd, void *__buf, size_t __nbytes)
00036 {
00037   if (__bos0 (__buf) != (size_t) -1)
00038     {
00039       if (!__builtin_constant_p (__nbytes))
00040        return __read_chk (__fd, __buf, __nbytes, __bos0 (__buf));
00041 
00042       if (__nbytes > __bos0 (__buf))
00043        return __read_chk_warn (__fd, __buf, __nbytes, __bos0 (__buf));
00044     }
00045   return __read_alias (__fd, __buf, __nbytes);
00046 }
00047 
00048 #ifdef __USE_UNIX98
00049 extern ssize_t __pread_chk (int __fd, void *__buf, size_t __nbytes,
00050                          __off_t __offset, size_t __bufsize) __wur;
00051 extern ssize_t __pread64_chk (int __fd, void *__buf, size_t __nbytes,
00052                            __off64_t __offset, size_t __bufsize) __wur;
00053 extern ssize_t __REDIRECT (__pread_alias,
00054                         (int __fd, void *__buf, size_t __nbytes,
00055                          __off_t __offset), pread) __wur;
00056 extern ssize_t __REDIRECT (__pread64_alias,
00057                         (int __fd, void *__buf, size_t __nbytes,
00058                          __off64_t __offset), pread64) __wur;
00059 extern ssize_t __REDIRECT (__pread_chk_warn,
00060                         (int __fd, void *__buf, size_t __nbytes,
00061                          __off_t __offset, size_t __bufsize), __pread_chk)
00062      __wur __warnattr ("pread called with bigger length than size of "
00063                      "the destination buffer");
00064 extern ssize_t __REDIRECT (__pread64_chk_warn,
00065                         (int __fd, void *__buf, size_t __nbytes,
00066                          __off64_t __offset, size_t __bufsize),
00067                          __pread64_chk)
00068      __wur __warnattr ("pread64 called with bigger length than size of "
00069                      "the destination buffer");
00070 
00071 # ifndef __USE_FILE_OFFSET64
00072 __extern_always_inline __wur ssize_t
00073 pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset)
00074 {
00075   if (__bos0 (__buf) != (size_t) -1)
00076     {
00077       if (!__builtin_constant_p (__nbytes))
00078        return __pread_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
00079 
00080       if ( __nbytes > __bos0 (__buf))
00081        return __pread_chk_warn (__fd, __buf, __nbytes, __offset,
00082                              __bos0 (__buf));
00083     }
00084   return __pread_alias (__fd, __buf, __nbytes, __offset);
00085 }
00086 # else
00087 __extern_always_inline __wur ssize_t
00088 pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
00089 {
00090   if (__bos0 (__buf) != (size_t) -1)
00091     {
00092       if (!__builtin_constant_p (__nbytes))
00093        return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
00094 
00095       if ( __nbytes > __bos0 (__buf))
00096        return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
00097                                __bos0 (__buf));
00098     }
00099 
00100   return __pread64_alias (__fd, __buf, __nbytes, __offset);
00101 }
00102 # endif
00103 
00104 # ifdef __USE_LARGEFILE64
00105 __extern_always_inline __wur ssize_t
00106 pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
00107 {
00108   if (__bos0 (__buf) != (size_t) -1)
00109     {
00110       if (!__builtin_constant_p (__nbytes))
00111        return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
00112 
00113       if ( __nbytes > __bos0 (__buf))
00114        return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
00115                                __bos0 (__buf));
00116     }
00117 
00118   return __pread64_alias (__fd, __buf, __nbytes, __offset);
00119 }
00120 # endif
00121 #endif
00122 
00123 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
00124 extern ssize_t __readlink_chk (__const char *__restrict __path,
00125                             char *__restrict __buf, size_t __len,
00126                             size_t __buflen)
00127      __THROW __nonnull ((1, 2)) __wur;
00128 extern ssize_t __REDIRECT_NTH (__readlink_alias,
00129                             (__const char *__restrict __path,
00130                             char *__restrict __buf, size_t __len), readlink)
00131      __nonnull ((1, 2)) __wur;
00132 extern ssize_t __REDIRECT_NTH (__readlink_chk_warn,
00133                             (__const char *__restrict __path,
00134                             char *__restrict __buf, size_t __len,
00135                             size_t __buflen), __readlink_chk)
00136      __nonnull ((1, 2)) __wur __warnattr ("readlink called with bigger length "
00137                                      "than size of destination buffer");
00138 
00139 __extern_always_inline __nonnull ((1, 2)) __wur ssize_t
00140 __NTH (readlink (__const char *__restrict __path, char *__restrict __buf,
00141                size_t __len))
00142 {
00143   if (__bos (__buf) != (size_t) -1)
00144     {
00145       if (!__builtin_constant_p (__len))
00146        return __readlink_chk (__path, __buf, __len, __bos (__buf));
00147 
00148       if ( __len > __bos (__buf))
00149        return __readlink_chk_warn (__path, __buf, __len, __bos (__buf));
00150     }
00151   return __readlink_alias (__path, __buf, __len);
00152 }
00153 #endif
00154 
00155 #ifdef __USE_ATFILE
00156 extern ssize_t __readlinkat_chk (int __fd, __const char *__restrict __path,
00157                              char *__restrict __buf, size_t __len,
00158                              size_t __buflen)
00159      __THROW __nonnull ((2, 3)) __wur;
00160 extern ssize_t __REDIRECT_NTH (__readlinkat_alias,
00161                             (int __fd, __const char *__restrict __path,
00162                             char *__restrict __buf, size_t __len),
00163                             readlinkat)
00164      __nonnull ((2, 3)) __wur;
00165 extern ssize_t __REDIRECT_NTH (__readlinkat_chk_warn,
00166                             (int __fd, __const char *__restrict __path,
00167                             char *__restrict __buf, size_t __len,
00168                             size_t __buflen), __readlinkat_chk)
00169      __nonnull ((2, 3)) __wur __warnattr ("readlinkat called with bigger "
00170                                      "length than size of destination "
00171                                      "buffer");
00172 
00173 __extern_always_inline __nonnull ((2, 3)) __wur ssize_t
00174 __NTH (readlinkat (int __fd, __const char *__restrict __path,
00175                  char *__restrict __buf, size_t __len))
00176 {
00177   if (__bos (__buf) != (size_t) -1)
00178     {
00179       if (!__builtin_constant_p (__len))
00180        return __readlinkat_chk (__fd, __path, __buf, __len, __bos (__buf));
00181 
00182       if (__len > __bos (__buf))
00183        return __readlinkat_chk_warn (__fd, __path, __buf, __len,
00184                                   __bos (__buf));
00185     }
00186   return __readlinkat_alias (__fd, __path, __buf, __len);
00187 }
00188 #endif
00189 
00190 extern char *__getcwd_chk (char *__buf, size_t __size, size_t __buflen)
00191      __THROW __wur;
00192 extern char *__REDIRECT_NTH (__getcwd_alias,
00193                           (char *__buf, size_t __size), getcwd) __wur;
00194 extern char *__REDIRECT_NTH (__getcwd_chk_warn,
00195                           (char *__buf, size_t __size, size_t __buflen),
00196                           __getcwd_chk)
00197      __wur __warnattr ("getcwd caller with bigger length than size of "
00198                      "destination buffer");
00199 
00200 __extern_always_inline __wur char *
00201 __NTH (getcwd (char *__buf, size_t __size))
00202 {
00203   if (__bos (__buf) != (size_t) -1)
00204     {
00205       if (!__builtin_constant_p (__size))
00206        return __getcwd_chk (__buf, __size, __bos (__buf));
00207 
00208       if (__size > __bos (__buf))
00209        return __getcwd_chk_warn (__buf, __size, __bos (__buf));
00210     }
00211   return __getcwd_alias (__buf, __size);
00212 }
00213 
00214 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
00215 extern char *__getwd_chk (char *__buf, size_t buflen)
00216      __THROW __nonnull ((1)) __wur;
00217 extern char *__REDIRECT_NTH (__getwd_warn, (char *__buf), getwd)
00218      __nonnull ((1)) __wur __warnattr ("please use getcwd instead, as getwd "
00219                                    "doesn't specify buffer size");
00220 
00221 __extern_always_inline __nonnull ((1)) __attribute_deprecated__ __wur char *
00222 __NTH (getwd (char *__buf))
00223 {
00224   if (__bos (__buf) != (size_t) -1)
00225     return __getwd_chk (__buf, __bos (__buf));
00226   return __getwd_warn (__buf);
00227 }
00228 #endif
00229 
00230 extern size_t __confstr_chk (int __name, char *__buf, size_t __len,
00231                           size_t __buflen) __THROW;
00232 extern size_t __REDIRECT_NTH (__confstr_alias, (int __name, char *__buf,
00233                                           size_t __len), confstr);
00234 extern size_t __REDIRECT_NTH (__confstr_chk_warn,
00235                            (int __name, char *__buf, size_t __len,
00236                             size_t __buflen), __confstr_chk)
00237      __warnattr ("confstr called with bigger length than size of destination "
00238                "buffer");
00239 
00240 __extern_always_inline size_t
00241 __NTH (confstr (int __name, char *__buf, size_t __len))
00242 {
00243   if (__bos (__buf) != (size_t) -1)
00244     {
00245       if (!__builtin_constant_p (__len))
00246        return __confstr_chk (__name, __buf, __len, __bos (__buf));
00247 
00248       if (__bos (__buf) < __len)
00249        return __confstr_chk_warn (__name, __buf, __len, __bos (__buf));
00250     }
00251   return __confstr_alias (__name, __buf, __len);
00252 }
00253 
00254 
00255 extern int __getgroups_chk (int __size, __gid_t __list[], size_t __listlen)
00256      __THROW __wur;
00257 extern int __REDIRECT_NTH (__getgroups_alias, (int __size, __gid_t __list[]),
00258                         getgroups) __wur;
00259 extern int __REDIRECT_NTH (__getgroups_chk_warn,
00260                         (int __size, __gid_t __list[], size_t __listlen),
00261                         __getgroups_chk)
00262      __wur __warnattr ("getgroups called with bigger group count than what "
00263                      "can fit into destination buffer");
00264 
00265 __extern_always_inline int
00266 __NTH (getgroups (int __size, __gid_t __list[]))
00267 {
00268   if (__bos (__list) != (size_t) -1)
00269     {
00270       if (!__builtin_constant_p (__size) || __size < 0)
00271        return __getgroups_chk (__size, __list, __bos (__list));
00272 
00273       if (__size * sizeof (__gid_t) > __bos (__list))
00274        return __getgroups_chk_warn (__size, __list, __bos (__list));
00275     }
00276   return __getgroups_alias (__size, __list);
00277 }
00278 
00279 
00280 extern int __ttyname_r_chk (int __fd, char *__buf, size_t __buflen,
00281                          size_t __nreal) __THROW __nonnull ((2));
00282 extern int __REDIRECT_NTH (__ttyname_r_alias, (int __fd, char *__buf,
00283                                           size_t __buflen), ttyname_r)
00284      __nonnull ((2));
00285 extern int __REDIRECT_NTH (__ttyname_r_chk_warn,
00286                         (int __fd, char *__buf, size_t __buflen,
00287                          size_t __nreal), __ttyname_r_chk)
00288      __nonnull ((2)) __warnattr ("ttyname_r called with bigger buflen than "
00289                              "size of destination buffer");
00290 
00291 __extern_always_inline int
00292 __NTH (ttyname_r (int __fd, char *__buf, size_t __buflen))
00293 {
00294   if (__bos (__buf) != (size_t) -1)
00295     {
00296       if (!__builtin_constant_p (__buflen))
00297        return __ttyname_r_chk (__fd, __buf, __buflen, __bos (__buf));
00298 
00299       if (__buflen > __bos (__buf))
00300        return __ttyname_r_chk_warn (__fd, __buf, __buflen, __bos (__buf));
00301     }
00302   return __ttyname_r_alias (__fd, __buf, __buflen);
00303 }
00304 
00305 
00306 #if defined __USE_REENTRANT || defined __USE_POSIX199506
00307 extern int __getlogin_r_chk (char *__buf, size_t __buflen, size_t __nreal)
00308      __nonnull ((1));
00309 extern int __REDIRECT (__getlogin_r_alias, (char *__buf, size_t __buflen),
00310                      getlogin_r) __nonnull ((1));
00311 extern int __REDIRECT (__getlogin_r_chk_warn,
00312                      (char *__buf, size_t __buflen, size_t __nreal),
00313                      __getlogin_r_chk)
00314      __nonnull ((1)) __warnattr ("getlogin_r called with bigger buflen than "
00315                              "size of destination buffer");
00316 
00317 __extern_always_inline int
00318 getlogin_r (char *__buf, size_t __buflen)
00319 {
00320   if (__bos (__buf) != (size_t) -1)
00321     {
00322       if (!__builtin_constant_p (__buflen))
00323        return __getlogin_r_chk (__buf, __buflen, __bos (__buf));
00324 
00325       if (__buflen > __bos (__buf))
00326        return __getlogin_r_chk_warn (__buf, __buflen, __bos (__buf));
00327     }
00328   return __getlogin_r_alias (__buf, __buflen);
00329 }
00330 #endif
00331 
00332 
00333 #if defined __USE_BSD || defined __USE_UNIX98
00334 extern int __gethostname_chk (char *__buf, size_t __buflen, size_t __nreal)
00335      __THROW __nonnull ((1));
00336 extern int __REDIRECT_NTH (__gethostname_alias, (char *__buf, size_t __buflen),
00337                         gethostname) __nonnull ((1));
00338 extern int __REDIRECT_NTH (__gethostname_chk_warn,
00339                         (char *__buf, size_t __buflen, size_t __nreal),
00340                         __gethostname_chk)
00341      __nonnull ((1)) __warnattr ("gethostname called with bigger buflen than "
00342                              "size of destination buffer");
00343 
00344 __extern_always_inline int
00345 __NTH (gethostname (char *__buf, size_t __buflen))
00346 {
00347   if (__bos (__buf) != (size_t) -1)
00348     {
00349       if (!__builtin_constant_p (__buflen))
00350        return __gethostname_chk (__buf, __buflen, __bos (__buf));
00351 
00352       if (__buflen > __bos (__buf))
00353        return __gethostname_chk_warn (__buf, __buflen, __bos (__buf));
00354     }
00355   return __gethostname_alias (__buf, __buflen);
00356 }
00357 #endif
00358 
00359 
00360 #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
00361 extern int __getdomainname_chk (char *__buf, size_t __buflen, size_t __nreal)
00362      __THROW __nonnull ((1)) __wur;
00363 extern int __REDIRECT_NTH (__getdomainname_alias, (char *__buf,
00364                                              size_t __buflen),
00365                         getdomainname) __nonnull ((1)) __wur;
00366 extern int __REDIRECT_NTH (__getdomainname_chk_warn,
00367                         (char *__buf, size_t __buflen, size_t __nreal),
00368                         __getdomainname_chk)
00369      __nonnull ((1)) __wur __warnattr ("getdomainname called with bigger "
00370                                    "buflen than size of destination "
00371                                    "buffer");
00372 
00373 __extern_always_inline int
00374 __NTH (getdomainname (char *__buf, size_t __buflen))
00375 {
00376   if (__bos (__buf) != (size_t) -1)
00377     {
00378       if (!__builtin_constant_p (__buflen))
00379        return __getdomainname_chk (__buf, __buflen, __bos (__buf));
00380 
00381       if (__buflen > __bos (__buf))
00382        return __getdomainname_chk_warn (__buf, __buflen, __bos (__buf));
00383     }
00384   return __getdomainname_alias (__buf, __buflen);
00385 }
00386 #endif