Back to index

glibc  2.9
stdlib.h
Go to the documentation of this file.
00001 /* Checking macros for stdlib functions.
00002    Copyright (C) 2005, 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 _STDLIB_H
00021 # error "Never include <bits/stdlib.h> directly; use <stdlib.h> instead."
00022 #endif
00023 
00024 extern char *__realpath_chk (__const char *__restrict __name,
00025                           char *__restrict __resolved,
00026                           size_t __resolvedlen) __THROW __wur;
00027 extern char *__REDIRECT_NTH (__realpath_alias,
00028                           (__const char *__restrict __name,
00029                            char *__restrict __resolved), realpath) __wur;
00030 extern char *__REDIRECT_NTH (__realpath_chk_warn,
00031                           (__const char *__restrict __name,
00032                            char *__restrict __resolved,
00033                            size_t __resolvedlen), __realpath_chk) __wur
00034      __warnattr ("second argument of realpath must be either NULL or at "
00035                "least PATH_MAX bytes long buffer");
00036 
00037 __extern_always_inline __wur char *
00038 __NTH (realpath (__const char *__restrict __name, char *__restrict __resolved))
00039 {
00040   if (__bos (__resolved) != (size_t) -1)
00041     {
00042 #if defined _LIBC_LIMITS_H_ && defined PATH_MAX
00043       if (__bos (__resolved) < PATH_MAX)
00044        return __realpath_chk_warn (__name, __resolved, __bos (__resolved));
00045 #endif
00046       return __realpath_chk (__name, __resolved, __bos (__resolved));
00047     }
00048 
00049   return __realpath_alias (__name, __resolved);
00050 }
00051 
00052 
00053 extern int __ptsname_r_chk (int __fd, char *__buf, size_t __buflen,
00054                          size_t __nreal) __THROW __nonnull ((2));
00055 extern int __REDIRECT_NTH (__ptsname_r_alias, (int __fd, char *__buf,
00056                                           size_t __buflen), ptsname_r)
00057      __nonnull ((2));
00058 extern int __REDIRECT_NTH (__ptsname_r_chk_warn,
00059                         (int __fd, char *__buf, size_t __buflen,
00060                          size_t __nreal), __ptsname_r_chk)
00061      __nonnull ((2)) __warnattr ("ptsname_r called with buflen bigger than "
00062                              "size of buf");
00063 
00064 __extern_always_inline int
00065 __NTH (ptsname_r (int __fd, char *__buf, size_t __buflen))
00066 {
00067   if (__bos (__buf) != (size_t) -1)
00068     {
00069       if (!__builtin_constant_p (__buflen))
00070        return __ptsname_r_chk (__fd, __buf, __buflen, __bos (__buf));
00071       if (__buflen > __bos (__buf))
00072        return __ptsname_r_chk_warn (__fd, __buf, __buflen, __bos (__buf));
00073     }
00074   return __ptsname_r_alias (__fd, __buf, __buflen);
00075 }
00076 
00077 
00078 extern int __wctomb_chk (char *__s, wchar_t __wchar, size_t __buflen)
00079   __THROW __wur;
00080 extern int __REDIRECT_NTH (__wctomb_alias, (char *__s, wchar_t __wchar),
00081                         wctomb) __wur;
00082 
00083 __extern_always_inline __wur int
00084 __NTH (wctomb (char *__s, wchar_t __wchar))
00085 {
00086   /* We would have to include <limits.h> to get a definition of MB_LEN_MAX.
00087      But this would only disturb the namespace.  So we define our own
00088      version here.  */
00089 #define __STDLIB_MB_LEN_MAX 16
00090 #if defined MB_LEN_MAX && MB_LEN_MAX != __STDLIB_MB_LEN_MAX
00091 # error "Assumed value of MB_LEN_MAX wrong"
00092 #endif
00093   if (__bos (__s) != (size_t) -1 && __STDLIB_MB_LEN_MAX > __bos (__s))
00094     return __wctomb_chk (__s, __wchar, __bos (__s));
00095   return __wctomb_alias (__s, __wchar);
00096 }
00097 
00098 
00099 extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,
00100                            __const char *__restrict __src,
00101                            size_t __len, size_t __dstlen) __THROW;
00102 extern size_t __REDIRECT_NTH (__mbstowcs_alias,
00103                            (wchar_t *__restrict __dst,
00104                             __const char *__restrict __src,
00105                             size_t __len), mbstowcs);
00106 extern size_t __REDIRECT_NTH (__mbstowcs_chk_warn,
00107                            (wchar_t *__restrict __dst,
00108                             __const char *__restrict __src,
00109                             size_t __len, size_t __dstlen), __mbstowcs_chk)
00110      __warnattr ("mbstowcs called with dst buffer smaller than len "
00111                "* sizeof (wchar_t)");
00112 
00113 __extern_always_inline size_t
00114 __NTH (mbstowcs (wchar_t *__restrict __dst, __const char *__restrict __src,
00115                size_t __len))
00116 {
00117   if (__bos (__dst) != (size_t) -1)
00118     {
00119       if (!__builtin_constant_p (__len))
00120        return __mbstowcs_chk (__dst, __src, __len,
00121                             __bos (__dst) / sizeof (wchar_t));
00122 
00123       if (__len > __bos (__dst) / sizeof (wchar_t))
00124        return __mbstowcs_chk_warn (__dst, __src, __len,
00125                                  __bos (__dst) / sizeof (wchar_t));
00126     }
00127   return __mbstowcs_alias (__dst, __src, __len);
00128 }
00129 
00130 
00131 extern size_t __wcstombs_chk (char *__restrict __dst,
00132                            __const wchar_t *__restrict __src,
00133                            size_t __len, size_t __dstlen) __THROW;
00134 extern size_t __REDIRECT_NTH (__wcstombs_alias,
00135                            (char *__restrict __dst,
00136                             __const wchar_t *__restrict __src,
00137                             size_t __len), wcstombs);
00138 extern size_t __REDIRECT_NTH (__wcstombs_chk_warn,
00139                            (char *__restrict __dst,
00140                             __const wchar_t *__restrict __src,
00141                             size_t __len, size_t __dstlen), __wcstombs_chk)
00142      __warnattr ("wcstombs called with dst buffer smaller than len");
00143 
00144 __extern_always_inline size_t
00145 __NTH (wcstombs (char *__restrict __dst, __const wchar_t *__restrict __src,
00146                size_t __len))
00147 {
00148   if (__bos (__dst) != (size_t) -1)
00149     {
00150       if (!__builtin_constant_p (__len))
00151        return __wcstombs_chk (__dst, __src, __len, __bos (__dst));
00152       if (__len > __bos (__dst))
00153        return __wcstombs_chk_warn (__dst, __src, __len, __bos (__dst));
00154     }
00155   return __wcstombs_alias (__dst, __src, __len);
00156 }