[BZ #4773]
[glibc.git] / stdlib / bits / stdlib.h
blob7ee7bf55877a2e4417bbe6ff966e102e23eb9bd8
1 /* Checking macros for stdlib functions.
2 Copyright (C) 2005, 2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _STDLIB_H
21 # error "Never include <bits/stdlib.h> directly; use <stdlib.h> instead."
22 #endif
24 extern char *__realpath_chk (__const char *__restrict __name,
25 char *__restrict __resolved,
26 size_t __resolvedlen) __THROW __wur;
27 extern char *__REDIRECT_NTH (__realpath_alias,
28 (__const char *__restrict __name,
29 char *__restrict __resolved), realpath) __wur;
31 __extern_always_inline __wur char *
32 __NTH (realpath (__const char *__restrict __name, char *__restrict __resolved))
34 if (__bos (__resolved) != (size_t) -1)
35 return __realpath_chk (__name, __resolved, __bos (__resolved));
37 return __realpath_alias (__name, __resolved);
41 extern int __ptsname_r_chk (int __fd, char *__buf, size_t __buflen,
42 size_t __nreal) __THROW __nonnull ((2));
43 extern int __REDIRECT_NTH (__ptsname_r_alias, (int __fd, char *__buf,
44 size_t __buflen), ptsname_r)
45 __nonnull ((2));
47 __extern_always_inline int
48 __NTH (ptsname_r (int __fd, char *__buf, size_t __buflen))
50 if (__bos (__buf) != (size_t) -1
51 && (!__builtin_constant_p (__buflen) || __buflen > __bos (__buf)))
52 return __ptsname_r_chk (__fd, __buf, __buflen, __bos (__buf));
53 return __ptsname_r_alias (__fd, __buf, __buflen);
57 extern int __wctomb_chk (char *__s, wchar_t __wchar, size_t __buflen)
58 __THROW __wur;
59 extern int __REDIRECT_NTH (__wctomb_alias, (char *__s, wchar_t __wchar),
60 wctomb) __wur;
62 __extern_always_inline __wur int
63 __NTH (wctomb (char *__s, wchar_t __wchar))
65 /* We would have to include <limits.h> to get a definition of MB_LEN_MAX.
66 But this would only disturb the namespace. So we define our own
67 version here. */
68 #define __STDLIB_MB_LEN_MAX 16
69 #if defined MB_LEN_MAX && MB_LEN_MAX != __STDLIB_MB_LEN_MAX
70 # error "Assumed value of MB_LEN_MAX wrong"
71 #endif
72 if (__bos (__s) != (size_t) -1 && __STDLIB_MB_LEN_MAX > __bos (__s))
73 return __wctomb_chk (__s, __wchar, __bos (__s));
74 return __wctomb_alias (__s, __wchar);
78 extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,
79 __const char *__restrict __src,
80 size_t __len, size_t __dstlen) __THROW;
81 extern size_t __REDIRECT_NTH (__mbstowcs_alias,
82 (wchar_t *__restrict __dst,
83 __const char *__restrict __src,
84 size_t __len), mbstowcs);
86 __extern_always_inline size_t
87 __NTH (mbstowcs (wchar_t *__restrict __dst, __const char *__restrict __src,
88 size_t __len))
90 if (__bos (__dst) != (size_t) -1
91 && (!__builtin_constant_p (__len)
92 || __len > __bos (__dst) / sizeof (wchar_t)))
93 return __mbstowcs_chk (__dst, __src, __len,
94 __bos (__dst) / sizeof (wchar_t));
95 return __mbstowcs_alias (__dst, __src, __len);
99 extern size_t __wcstombs_chk (char *__restrict __dst,
100 __const wchar_t *__restrict __src,
101 size_t __len, size_t __dstlen) __THROW;
102 extern size_t __REDIRECT_NTH (__wcstombs_alias,
103 (char *__restrict __dst,
104 __const wchar_t *__restrict __src,
105 size_t __len), wcstombs);
107 __extern_always_inline size_t
108 __NTH (wcstombs (char *__restrict __dst, __const wchar_t *__restrict __src,
109 size_t __len))
111 if (__bos (__dst) != (size_t) -1
112 && (!__builtin_constant_p (__len) || __len > __bos (__dst)))
113 return __wcstombs_chk (__dst, __src, __len, __bos (__dst));
114 return __wcstombs_alias (__dst, __src, __len);