]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdlib/bits/stdlib.h
Update copyright notices with scripts/update-copyrights.
[thirdparty/glibc.git] / stdlib / bits / stdlib.h
CommitLineData
b799f91d 1/* Checking macros for stdlib functions.
568035b7 2 Copyright (C) 2005-2013 Free Software Foundation, Inc.
b799f91d
UD
3 This file is part of the GNU C Library.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
b799f91d
UD
18
19#ifndef _STDLIB_H
20# error "Never include <bits/stdlib.h> directly; use <stdlib.h> instead."
21#endif
22
a784e502 23extern char *__realpath_chk (const char *__restrict __name,
b799f91d
UD
24 char *__restrict __resolved,
25 size_t __resolvedlen) __THROW __wur;
5c08f24c 26extern char *__REDIRECT_NTH (__realpath_alias,
a784e502 27 (const char *__restrict __name,
5c08f24c 28 char *__restrict __resolved), realpath) __wur;
d6cd6bf4 29extern char *__REDIRECT_NTH (__realpath_chk_warn,
a784e502 30 (const char *__restrict __name,
d6cd6bf4
UD
31 char *__restrict __resolved,
32 size_t __resolvedlen), __realpath_chk) __wur
33 __warnattr ("second argument of realpath must be either NULL or at "
34 "least PATH_MAX bytes long buffer");
b799f91d 35
5ac3ea17 36__fortify_function __wur char *
a784e502 37__NTH (realpath (const char *__restrict __name, char *__restrict __resolved))
b799f91d
UD
38{
39 if (__bos (__resolved) != (size_t) -1)
d6cd6bf4
UD
40 {
41#if defined _LIBC_LIMITS_H_ && defined PATH_MAX
42 if (__bos (__resolved) < PATH_MAX)
43 return __realpath_chk_warn (__name, __resolved, __bos (__resolved));
44#endif
45 return __realpath_chk (__name, __resolved, __bos (__resolved));
46 }
b799f91d
UD
47
48 return __realpath_alias (__name, __resolved);
49}
50
51
52extern int __ptsname_r_chk (int __fd, char *__buf, size_t __buflen,
53 size_t __nreal) __THROW __nonnull ((2));
5c08f24c
UD
54extern int __REDIRECT_NTH (__ptsname_r_alias, (int __fd, char *__buf,
55 size_t __buflen), ptsname_r)
56 __nonnull ((2));
d6cd6bf4
UD
57extern int __REDIRECT_NTH (__ptsname_r_chk_warn,
58 (int __fd, char *__buf, size_t __buflen,
59 size_t __nreal), __ptsname_r_chk)
60 __nonnull ((2)) __warnattr ("ptsname_r called with buflen bigger than "
61 "size of buf");
b799f91d 62
5ac3ea17 63__fortify_function int
dc4bb1c2 64__NTH (ptsname_r (int __fd, char *__buf, size_t __buflen))
b799f91d 65{
d6cd6bf4
UD
66 if (__bos (__buf) != (size_t) -1)
67 {
68 if (!__builtin_constant_p (__buflen))
69 return __ptsname_r_chk (__fd, __buf, __buflen, __bos (__buf));
70 if (__buflen > __bos (__buf))
71 return __ptsname_r_chk_warn (__fd, __buf, __buflen, __bos (__buf));
72 }
b799f91d
UD
73 return __ptsname_r_alias (__fd, __buf, __buflen);
74}
75
76
77extern int __wctomb_chk (char *__s, wchar_t __wchar, size_t __buflen)
78 __THROW __wur;
0396de51
UD
79extern int __REDIRECT_NTH (__wctomb_alias, (char *__s, wchar_t __wchar),
80 wctomb) __wur;
b799f91d 81
5ac3ea17 82__fortify_function __wur int
dc4bb1c2 83__NTH (wctomb (char *__s, wchar_t __wchar))
b799f91d
UD
84{
85 /* We would have to include <limits.h> to get a definition of MB_LEN_MAX.
86 But this would only disturb the namespace. So we define our own
87 version here. */
88#define __STDLIB_MB_LEN_MAX 16
89#if defined MB_LEN_MAX && MB_LEN_MAX != __STDLIB_MB_LEN_MAX
90# error "Assumed value of MB_LEN_MAX wrong"
91#endif
92 if (__bos (__s) != (size_t) -1 && __STDLIB_MB_LEN_MAX > __bos (__s))
93 return __wctomb_chk (__s, __wchar, __bos (__s));
94 return __wctomb_alias (__s, __wchar);
95}
02ca3541
UD
96
97
98extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,
a784e502 99 const char *__restrict __src,
02ca3541
UD
100 size_t __len, size_t __dstlen) __THROW;
101extern size_t __REDIRECT_NTH (__mbstowcs_alias,
102 (wchar_t *__restrict __dst,
a784e502 103 const char *__restrict __src,
02ca3541 104 size_t __len), mbstowcs);
d6cd6bf4
UD
105extern size_t __REDIRECT_NTH (__mbstowcs_chk_warn,
106 (wchar_t *__restrict __dst,
a784e502 107 const char *__restrict __src,
d6cd6bf4
UD
108 size_t __len, size_t __dstlen), __mbstowcs_chk)
109 __warnattr ("mbstowcs called with dst buffer smaller than len "
110 "* sizeof (wchar_t)");
02ca3541 111
5ac3ea17 112__fortify_function size_t
a784e502 113__NTH (mbstowcs (wchar_t *__restrict __dst, const char *__restrict __src,
dc4bb1c2 114 size_t __len))
02ca3541 115{
d6cd6bf4
UD
116 if (__bos (__dst) != (size_t) -1)
117 {
118 if (!__builtin_constant_p (__len))
119 return __mbstowcs_chk (__dst, __src, __len,
120 __bos (__dst) / sizeof (wchar_t));
121
122 if (__len > __bos (__dst) / sizeof (wchar_t))
123 return __mbstowcs_chk_warn (__dst, __src, __len,
124 __bos (__dst) / sizeof (wchar_t));
125 }
02ca3541
UD
126 return __mbstowcs_alias (__dst, __src, __len);
127}
128
129
130extern size_t __wcstombs_chk (char *__restrict __dst,
a784e502 131 const wchar_t *__restrict __src,
02ca3541
UD
132 size_t __len, size_t __dstlen) __THROW;
133extern size_t __REDIRECT_NTH (__wcstombs_alias,
134 (char *__restrict __dst,
a784e502 135 const wchar_t *__restrict __src,
02ca3541 136 size_t __len), wcstombs);
d6cd6bf4
UD
137extern size_t __REDIRECT_NTH (__wcstombs_chk_warn,
138 (char *__restrict __dst,
a784e502 139 const wchar_t *__restrict __src,
d6cd6bf4
UD
140 size_t __len, size_t __dstlen), __wcstombs_chk)
141 __warnattr ("wcstombs called with dst buffer smaller than len");
02ca3541 142
5ac3ea17 143__fortify_function size_t
a784e502 144__NTH (wcstombs (char *__restrict __dst, const wchar_t *__restrict __src,
dc4bb1c2 145 size_t __len))
02ca3541 146{
d6cd6bf4
UD
147 if (__bos (__dst) != (size_t) -1)
148 {
149 if (!__builtin_constant_p (__len))
150 return __wcstombs_chk (__dst, __src, __len, __bos (__dst));
151 if (__len > __bos (__dst))
152 return __wcstombs_chk_warn (__dst, __src, __len, __bos (__dst));
153 }
02ca3541
UD
154 return __wcstombs_alias (__dst, __src, __len);
155}