]>
Commit | Line | Data |
---|---|---|
b799f91d | 1 | /* Checking macros for stdlib functions. |
26420023 | 2 | Copyright (C) 2005-2025 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 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://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 | 23 | extern char *__realpath_chk (const char *__restrict __name, |
b799f91d UD |
24 | char *__restrict __resolved, |
25 | size_t __resolvedlen) __THROW __wur; | |
5c08f24c | 26 | extern char *__REDIRECT_NTH (__realpath_alias, |
a784e502 | 27 | (const char *__restrict __name, |
5c08f24c | 28 | char *__restrict __resolved), realpath) __wur; |
d6cd6bf4 | 29 | extern 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 | |
d39a893e AZ |
36 | __fortify_function __attribute_overloadable__ __wur char * |
37 | __NTH (realpath (const char *__restrict __name, | |
38 | __fortify_clang_overload_arg (char *, __restrict, __resolved))) | |
39 | #if defined _LIBC_LIMITS_H_ && defined PATH_MAX | |
40 | __fortify_clang_warning_only_if_bos_lt (PATH_MAX, __resolved, | |
41 | "second argument of realpath must be " | |
42 | "either NULL or at least PATH_MAX " | |
43 | "bytes long buffer") | |
44 | #endif | |
b799f91d | 45 | { |
39ca997a | 46 | size_t __sz = __glibc_objsize (__resolved); |
a643f60c | 47 | |
39ca997a | 48 | if (__sz == (size_t) -1) |
a643f60c SP |
49 | return __realpath_alias (__name, __resolved); |
50 | ||
d39a893e | 51 | #if !__fortify_use_clang && defined _LIBC_LIMITS_H_ && defined PATH_MAX |
39ca997a AS |
52 | if (__glibc_unsafe_len (PATH_MAX, sizeof (char), __sz)) |
53 | return __realpath_chk_warn (__name, __resolved, __sz); | |
d6cd6bf4 | 54 | #endif |
39ca997a | 55 | return __realpath_chk (__name, __resolved, __sz); |
b799f91d UD |
56 | } |
57 | ||
58 | ||
59 | extern int __ptsname_r_chk (int __fd, char *__buf, size_t __buflen, | |
06febd8c MS |
60 | size_t __nreal) __THROW __nonnull ((2)) |
61 | __attr_access ((__write_only__, 2, 3)); | |
5c08f24c UD |
62 | extern int __REDIRECT_NTH (__ptsname_r_alias, (int __fd, char *__buf, |
63 | size_t __buflen), ptsname_r) | |
06febd8c | 64 | __nonnull ((2)) __attr_access ((__write_only__, 2, 3)); |
d6cd6bf4 UD |
65 | extern int __REDIRECT_NTH (__ptsname_r_chk_warn, |
66 | (int __fd, char *__buf, size_t __buflen, | |
67 | size_t __nreal), __ptsname_r_chk) | |
68 | __nonnull ((2)) __warnattr ("ptsname_r called with buflen bigger than " | |
69 | "size of buf"); | |
b799f91d | 70 | |
d39a893e AZ |
71 | __fortify_function __attribute_overloadable__ int |
72 | __NTH (ptsname_r (int __fd, | |
73 | __fortify_clang_overload_arg (char *, ,__buf), | |
74 | size_t __buflen)) | |
75 | __fortify_clang_warning_only_if_bos_lt (__buflen, __buf, | |
76 | "ptsname_r called with buflen " | |
77 | "bigger than size of buf") | |
b799f91d | 78 | { |
a643f60c SP |
79 | return __glibc_fortify (ptsname_r, __buflen, sizeof (char), |
80 | __glibc_objsize (__buf), | |
81 | __fd, __buf, __buflen); | |
b799f91d UD |
82 | } |
83 | ||
84 | ||
85 | extern int __wctomb_chk (char *__s, wchar_t __wchar, size_t __buflen) | |
86 | __THROW __wur; | |
0396de51 UD |
87 | extern int __REDIRECT_NTH (__wctomb_alias, (char *__s, wchar_t __wchar), |
88 | wctomb) __wur; | |
b799f91d | 89 | |
d39a893e AZ |
90 | __fortify_function __attribute_overloadable__ __wur int |
91 | __NTH (wctomb (__fortify_clang_overload_arg (char *, ,__s), wchar_t __wchar)) | |
b799f91d UD |
92 | { |
93 | /* We would have to include <limits.h> to get a definition of MB_LEN_MAX. | |
94 | But this would only disturb the namespace. So we define our own | |
95 | version here. */ | |
96 | #define __STDLIB_MB_LEN_MAX 16 | |
97 | #if defined MB_LEN_MAX && MB_LEN_MAX != __STDLIB_MB_LEN_MAX | |
98 | # error "Assumed value of MB_LEN_MAX wrong" | |
99 | #endif | |
f9de8bfe SP |
100 | if (__glibc_objsize (__s) != (size_t) -1 |
101 | && __STDLIB_MB_LEN_MAX > __glibc_objsize (__s)) | |
102 | return __wctomb_chk (__s, __wchar, __glibc_objsize (__s)); | |
b799f91d UD |
103 | return __wctomb_alias (__s, __wchar); |
104 | } | |
02ca3541 UD |
105 | |
106 | ||
107 | extern size_t __mbstowcs_chk (wchar_t *__restrict __dst, | |
a784e502 | 108 | const char *__restrict __src, |
06febd8c MS |
109 | size_t __len, size_t __dstlen) __THROW |
110 | __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2)); | |
220b83d8 | 111 | extern size_t __REDIRECT_NTH (__mbstowcs_nulldst, |
464d189b NG |
112 | (wchar_t *__restrict __dst, |
113 | const char *__restrict __src, | |
220b83d8 | 114 | size_t __len), mbstowcs) |
464d189b | 115 | __attr_access ((__read_only__, 2)); |
02ca3541 UD |
116 | extern size_t __REDIRECT_NTH (__mbstowcs_alias, |
117 | (wchar_t *__restrict __dst, | |
a784e502 | 118 | const char *__restrict __src, |
06febd8c MS |
119 | size_t __len), mbstowcs) |
120 | __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2)); | |
d6cd6bf4 UD |
121 | extern size_t __REDIRECT_NTH (__mbstowcs_chk_warn, |
122 | (wchar_t *__restrict __dst, | |
a784e502 | 123 | const char *__restrict __src, |
d6cd6bf4 UD |
124 | size_t __len, size_t __dstlen), __mbstowcs_chk) |
125 | __warnattr ("mbstowcs called with dst buffer smaller than len " | |
126 | "* sizeof (wchar_t)"); | |
02ca3541 | 127 | |
d39a893e AZ |
128 | __fortify_function __attribute_overloadable__ size_t |
129 | __NTH (mbstowcs (__fortify_clang_overload_arg (wchar_t *, __restrict, __dst), | |
130 | const char *__restrict __src, | |
dc4bb1c2 | 131 | size_t __len)) |
d39a893e AZ |
132 | __fortify_clang_warning_only_if_bos0_lt2 (__len, __dst, sizeof (wchar_t), |
133 | "mbstowcs called with dst buffer " | |
134 | "smaller than len * sizeof (wchar_t)") | |
02ca3541 | 135 | { |
464d189b | 136 | if (__builtin_constant_p (__dst == NULL) && __dst == NULL) |
220b83d8 | 137 | return __mbstowcs_nulldst (__dst, __src, __len); |
464d189b NG |
138 | else |
139 | return __glibc_fortify_n (mbstowcs, __len, sizeof (wchar_t), | |
140 | __glibc_objsize (__dst), __dst, __src, __len); | |
02ca3541 UD |
141 | } |
142 | ||
02ca3541 | 143 | extern size_t __wcstombs_chk (char *__restrict __dst, |
a784e502 | 144 | const wchar_t *__restrict __src, |
06febd8c MS |
145 | size_t __len, size_t __dstlen) __THROW |
146 | __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2)); | |
02ca3541 UD |
147 | extern size_t __REDIRECT_NTH (__wcstombs_alias, |
148 | (char *__restrict __dst, | |
a784e502 | 149 | const wchar_t *__restrict __src, |
06febd8c MS |
150 | size_t __len), wcstombs) |
151 | __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2)); | |
d6cd6bf4 UD |
152 | extern size_t __REDIRECT_NTH (__wcstombs_chk_warn, |
153 | (char *__restrict __dst, | |
a784e502 | 154 | const wchar_t *__restrict __src, |
d6cd6bf4 UD |
155 | size_t __len, size_t __dstlen), __wcstombs_chk) |
156 | __warnattr ("wcstombs called with dst buffer smaller than len"); | |
02ca3541 | 157 | |
d39a893e AZ |
158 | __fortify_function __attribute_overloadable__ size_t |
159 | __NTH (wcstombs (__fortify_clang_overload_arg (char *, __restrict, __dst), | |
160 | const wchar_t *__restrict __src, | |
dc4bb1c2 | 161 | size_t __len)) |
02ca3541 | 162 | { |
a643f60c SP |
163 | return __glibc_fortify (wcstombs, __len, sizeof (char), |
164 | __glibc_objsize (__dst), | |
165 | __dst, __src, __len); | |
02ca3541 | 166 | } |