]>
Commit | Line | Data |
---|---|---|
8215c9ec | 1 | /* Checking macros for wchar functions. |
b037a293 | 2 | Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. |
8215c9ec 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 | |
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. */ | |
19 | ||
20 | #ifndef _WCHAR_H | |
21 | # error "Never include <bits/wchar.h> directly; use <wchar.h> instead." | |
22 | #endif | |
23 | ||
24 | ||
25 | extern wchar_t *__wmemcpy_chk (wchar_t *__restrict __s1, | |
26 | __const wchar_t *__restrict __s2, size_t __n, | |
27 | size_t __ns1) __THROW; | |
22870975 UD |
28 | extern wchar_t *__REDIRECT_NTH (__wmemcpy_alias, |
29 | (wchar_t *__restrict __s1, | |
30 | __const wchar_t *__restrict __s2, size_t __n), | |
31 | wmemcpy); | |
8215c9ec | 32 | |
b037a293 | 33 | __extern_always_inline wchar_t * |
dc4bb1c2 UD |
34 | __NTH (wmemcpy (wchar_t *__restrict __s1, __const wchar_t *__restrict __s2, |
35 | size_t __n)) | |
8215c9ec UD |
36 | { |
37 | if (__bos0 (__s1) != (size_t) -1) | |
38 | return __wmemcpy_chk (__s1, __s2, __n, __bos0 (__s1) / sizeof (wchar_t)); | |
39 | return __wmemcpy_alias (__s1, __s2, __n); | |
40 | } | |
41 | ||
42 | ||
43 | extern wchar_t *__wmemmove_chk (wchar_t *__s1, __const wchar_t *__s2, | |
44 | size_t __n, size_t __ns1) __THROW; | |
22870975 UD |
45 | extern wchar_t *__REDIRECT_NTH (__wmemmove_alias, (wchar_t *__s1, |
46 | __const wchar_t *__s2, | |
47 | size_t __n), wmemmove); | |
8215c9ec | 48 | |
b037a293 | 49 | __extern_always_inline wchar_t * |
dc4bb1c2 UD |
50 | __NTH (wmemmove (wchar_t *__restrict __s1, __const wchar_t *__restrict __s2, |
51 | size_t __n)) | |
8215c9ec UD |
52 | { |
53 | if (__bos0 (__s1) != (size_t) -1) | |
54 | return __wmemmove_chk (__s1, __s2, __n, __bos0 (__s1) / sizeof (wchar_t)); | |
55 | return __wmemmove_alias (__s1, __s2, __n); | |
56 | } | |
57 | ||
58 | ||
59 | #ifdef __USE_GNU | |
60 | extern wchar_t *__wmempcpy_chk (wchar_t *__restrict __s1, | |
61 | __const wchar_t *__restrict __s2, size_t __n, | |
62 | size_t __ns1) __THROW; | |
22870975 UD |
63 | extern wchar_t *__REDIRECT_NTH (__wmempcpy_alias, |
64 | (wchar_t *__restrict __s1, | |
65 | __const wchar_t *__restrict __s2, | |
66 | size_t __n), wmempcpy); | |
8215c9ec | 67 | |
b037a293 | 68 | __extern_always_inline wchar_t * |
dc4bb1c2 UD |
69 | __NTH (wmempcpy (wchar_t *__restrict __s1, __const wchar_t *__restrict __s2, |
70 | size_t __n)) | |
8215c9ec UD |
71 | { |
72 | if (__bos0 (__s1) != (size_t) -1) | |
73 | return __wmempcpy_chk (__s1, __s2, __n, __bos0 (__s1) / sizeof (wchar_t)); | |
74 | return __wmempcpy_alias (__s1, __s2, __n); | |
75 | } | |
76 | #endif | |
77 | ||
78 | ||
79 | extern wchar_t *__wmemset_chk (wchar_t *__s, wchar_t __c, size_t __n, | |
80 | size_t __ns) __THROW; | |
22870975 UD |
81 | extern wchar_t *__REDIRECT_NTH (__wmemset_alias, (wchar_t *__s, wchar_t __c, |
82 | size_t __n), wmemset); | |
8215c9ec | 83 | |
b037a293 | 84 | __extern_always_inline wchar_t * |
dc4bb1c2 | 85 | __NTH (wmemset (wchar_t *__restrict __s, wchar_t __c, size_t __n)) |
8215c9ec UD |
86 | { |
87 | if (__bos0 (__s) != (size_t) -1) | |
88 | return __wmemset_chk (__s, __c, __n, __bos0 (__s) / sizeof (wchar_t)); | |
89 | return __wmemset_alias (__s, __c, __n); | |
90 | } | |
91 | ||
92 | ||
93 | extern wchar_t *__wcscpy_chk (wchar_t *__restrict __dest, | |
94 | __const wchar_t *__restrict __src, | |
95 | size_t __n) __THROW; | |
22870975 UD |
96 | extern wchar_t *__REDIRECT_NTH (__wcscpy_alias, |
97 | (wchar_t *__restrict __dest, | |
98 | __const wchar_t *__restrict __src), wcscpy); | |
8215c9ec | 99 | |
b037a293 | 100 | __extern_always_inline wchar_t * |
dc4bb1c2 | 101 | __NTH (wcscpy (wchar_t *__dest, __const wchar_t *__src)) |
8215c9ec UD |
102 | { |
103 | if (__bos (__dest) != (size_t) -1) | |
104 | return __wcscpy_chk (__dest, __src, __bos (__dest) / sizeof (wchar_t)); | |
105 | return __wcscpy_alias (__dest, __src); | |
106 | } | |
107 | ||
108 | ||
109 | extern wchar_t *__wcpcpy_chk (wchar_t *__dest, __const wchar_t *__src, | |
110 | size_t __destlen) __THROW; | |
22870975 UD |
111 | extern wchar_t *__REDIRECT_NTH (__wcpcpy_alias, (wchar_t *__dest, |
112 | __const wchar_t *__src), | |
113 | wcpcpy); | |
8215c9ec | 114 | |
b037a293 | 115 | __extern_always_inline wchar_t * |
dc4bb1c2 | 116 | __NTH (wcpcpy (wchar_t *__dest, __const wchar_t *__src)) |
8215c9ec UD |
117 | { |
118 | if (__bos (__dest) != (size_t) -1) | |
119 | return __wcpcpy_chk (__dest, __src, __bos (__dest) / sizeof (wchar_t)); | |
120 | return __wcpcpy_alias (__dest, __src); | |
121 | } | |
122 | ||
123 | ||
124 | extern wchar_t *__wcsncpy_chk (wchar_t *__restrict __dest, | |
125 | __const wchar_t *__restrict __src, size_t __n, | |
126 | size_t __destlen) __THROW; | |
22870975 UD |
127 | extern wchar_t *__REDIRECT_NTH (__wcsncpy_alias, |
128 | (wchar_t *__restrict __dest, | |
129 | __const wchar_t *__restrict __src, | |
130 | size_t __n), wcsncpy); | |
8215c9ec | 131 | |
b037a293 | 132 | __extern_always_inline wchar_t * |
dc4bb1c2 | 133 | __NTH (wcsncpy (wchar_t *__dest, __const wchar_t *__src, size_t __n)) |
8215c9ec UD |
134 | { |
135 | if (__bos (__dest) != (size_t) -1 | |
136 | && (!__builtin_constant_p (__n) || __bos (__dest) >= __n)) | |
137 | return __wcsncpy_chk (__dest, __src, __n, | |
138 | __bos (__dest) / sizeof (wchar_t)); | |
139 | return __wcsncpy_alias (__dest, __src, __n); | |
140 | } | |
141 | ||
142 | ||
143 | extern wchar_t *__wcpncpy_chk (wchar_t *__restrict __dest, | |
144 | __const wchar_t *__restrict __src, size_t __n, | |
145 | size_t __destlen) __THROW; | |
22870975 UD |
146 | extern wchar_t *__REDIRECT_NTH (__wcpncpy_alias, |
147 | (wchar_t *__restrict __dest, | |
148 | __const wchar_t *__restrict __src, | |
149 | size_t __n), wcpncpy); | |
8215c9ec | 150 | |
b037a293 | 151 | __extern_always_inline wchar_t * |
dc4bb1c2 | 152 | __NTH (wcpncpy (wchar_t *__dest, __const wchar_t *__src, size_t __n)) |
8215c9ec UD |
153 | { |
154 | if (__bos (__dest) != (size_t) -1 | |
155 | && (!__builtin_constant_p (__n) || __bos (__dest) >= __n)) | |
156 | return __wcpncpy_chk (__dest, __src, __n, | |
157 | __bos (__dest) / sizeof (wchar_t)); | |
158 | return __wcpncpy_alias (__dest, __src, __n); | |
159 | } | |
160 | ||
161 | ||
162 | extern wchar_t *__wcscat_chk (wchar_t *__restrict __dest, | |
163 | __const wchar_t *__restrict __src, | |
164 | size_t __destlen) __THROW; | |
22870975 UD |
165 | extern wchar_t *__REDIRECT_NTH (__wcscat_alias, |
166 | (wchar_t *__restrict __dest, | |
167 | __const wchar_t *__restrict __src), wcscat); | |
8215c9ec | 168 | |
b037a293 | 169 | __extern_always_inline wchar_t * |
dc4bb1c2 | 170 | __NTH (wcscat (wchar_t *__dest, __const wchar_t *__src)) |
8215c9ec UD |
171 | { |
172 | if (__bos (__dest) != (size_t) -1) | |
173 | return __wcscat_chk (__dest, __src, __bos (__dest) / sizeof (wchar_t)); | |
174 | return __wcscat_alias (__dest, __src); | |
175 | } | |
176 | ||
177 | ||
178 | extern wchar_t *__wcsncat_chk (wchar_t *__restrict __dest, | |
179 | __const wchar_t *__restrict __src, | |
180 | size_t __n, size_t __destlen) __THROW; | |
22870975 UD |
181 | extern wchar_t *__REDIRECT_NTH (__wcsncat_alias, |
182 | (wchar_t *__restrict __dest, | |
183 | __const wchar_t *__restrict __src, | |
184 | size_t __n), wcsncat); | |
8215c9ec | 185 | |
b037a293 | 186 | __extern_always_inline wchar_t * |
dc4bb1c2 | 187 | __NTH (wcsncat (wchar_t *__dest, __const wchar_t *__src, size_t __n)) |
8215c9ec UD |
188 | { |
189 | if (__bos (__dest) != (size_t) -1) | |
190 | return __wcsncat_chk (__dest, __src, __n, | |
191 | __bos (__dest) / sizeof (wchar_t)); | |
192 | return __wcsncat_alias (__dest, __src, __n); | |
193 | } | |
194 | ||
195 | ||
196 | extern int __swprintf_chk (wchar_t *__restrict __s, size_t __n, | |
197 | int __flag, size_t __s_len, | |
198 | __const wchar_t *__restrict __format, ...) | |
199 | __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 6))) */; | |
200 | ||
201 | /* XXX We might want to have support in gcc for swprintf. */ | |
757beee1 | 202 | #define swprintf(s, n, ...) \ |
8215c9ec | 203 | (__bos (s) != (size_t) -1 || __USE_FORTIFY_LEVEL > 1 \ |
757beee1 UD |
204 | ? __swprintf_chk (s, n, __USE_FORTIFY_LEVEL - 1, __bos (s), __VA_ARGS__) \ |
205 | : swprintf (s, n, __VA_ARGS__)) | |
8215c9ec UD |
206 | |
207 | ||
208 | extern int __vswprintf_chk (wchar_t *__restrict __s, size_t __n, | |
209 | int __flag, size_t __s_len, | |
210 | __const wchar_t *__restrict __format, | |
211 | __gnuc_va_list __arg) | |
212 | __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 0))) */; | |
8215c9ec | 213 | |
c6251f03 RM |
214 | #define vswprintf(s, n, fmt, ap) \ |
215 | (__bos (s) != (size_t) -1 || __USE_FORTIFY_LEVEL > 1 \ | |
216 | ? __vswprintf_chk (s, n, __USE_FORTIFY_LEVEL - 1, __bos (s), fmt, ap) \ | |
217 | : vswprintf (s, n, fmt, ap)) | |
8215c9ec UD |
218 | |
219 | ||
220 | #if __USE_FORTIFY_LEVEL > 1 | |
221 | ||
76c98ee2 | 222 | extern int __fwprintf_chk (__FILE *__restrict __stream, int __flag, |
8215c9ec UD |
223 | __const wchar_t *__restrict __format, ...); |
224 | extern int __wprintf_chk (int __flag, __const wchar_t *__restrict __format, | |
225 | ...); | |
76c98ee2 | 226 | extern int __vfwprintf_chk (__FILE *__restrict __stream, int __flag, |
8215c9ec | 227 | __const wchar_t *__restrict __format, |
24452349 | 228 | __gnuc_va_list __ap); |
8215c9ec | 229 | extern int __vwprintf_chk (int __flag, __const wchar_t *__restrict __format, |
24452349 | 230 | __gnuc_va_list __ap); |
8215c9ec UD |
231 | |
232 | # define wprintf(...) \ | |
233 | __wprintf_chk (__USE_FORTIFY_LEVEL - 1, __VA_ARGS__) | |
234 | # define fwprintf(stream, ...) \ | |
235 | __fwprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) | |
236 | # define vwprintf(format, ap) \ | |
237 | __vwprintf_chk (__USE_FORTIFY_LEVEL - 1, format, ap) | |
238 | # define vfwprintf(stream, format, ap) \ | |
239 | __vfwprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, format, ap) | |
240 | ||
241 | #endif | |
242 | ||
243 | extern wchar_t *__fgetws_chk (wchar_t *__restrict __s, size_t __size, int __n, | |
76c98ee2 | 244 | __FILE *__restrict __stream) __wur; |
8215c9ec UD |
245 | extern wchar_t *__REDIRECT (__fgetws_alias, |
246 | (wchar_t *__restrict __s, int __n, | |
76c98ee2 | 247 | __FILE *__restrict __stream), fgetws) __wur; |
8215c9ec | 248 | |
b037a293 | 249 | __extern_always_inline __wur wchar_t * |
76c98ee2 | 250 | fgetws (wchar_t *__restrict __s, int __n, __FILE *__restrict __stream) |
8215c9ec UD |
251 | { |
252 | if (__bos (__s) != (size_t) -1 | |
253 | && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s))) | |
254 | return __fgetws_chk (__s, __bos (__s), __n, __stream); | |
255 | return __fgetws_alias (__s, __n, __stream); | |
256 | } | |
257 | ||
258 | #ifdef __USE_GNU | |
259 | extern wchar_t *__fgetws_unlocked_chk (wchar_t *__restrict __s, size_t __size, | |
76c98ee2 | 260 | int __n, __FILE *__restrict __stream) |
8215c9ec UD |
261 | __wur; |
262 | extern wchar_t *__REDIRECT (__fgetws_unlocked_alias, | |
263 | (wchar_t *__restrict __s, int __n, | |
76c98ee2 | 264 | __FILE *__restrict __stream), fgetws_unlocked) |
8215c9ec UD |
265 | __wur; |
266 | ||
b037a293 | 267 | __extern_always_inline __wur wchar_t * |
76c98ee2 | 268 | fgetws_unlocked (wchar_t *__restrict __s, int __n, __FILE *__restrict __stream) |
8215c9ec UD |
269 | { |
270 | if (__bos (__s) != (size_t) -1 | |
271 | && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s))) | |
272 | return __fgetws_unlocked_chk (__s, __bos (__s), __n, __stream); | |
273 | return __fgetws_unlocked_alias (__s, __n, __stream); | |
274 | } | |
275 | #endif | |
df6f8969 UD |
276 | |
277 | ||
278 | extern size_t __wcrtomb_chk (char *__s, wchar_t __wchar, mbstate_t *__p, | |
279 | size_t __buflen) __THROW __wur; | |
280 | extern size_t __REDIRECT_NTH (__wcrtomb_alias, | |
281 | (char *__restrict __s, wchar_t __wchar, | |
282 | mbstate_t *__restrict __ps), wcrtomb) __wur; | |
283 | ||
b037a293 | 284 | __extern_always_inline __wur size_t |
dc4bb1c2 | 285 | __NTH (wcrtomb (char *__s, wchar_t __wchar, mbstate_t *__ps)) |
df6f8969 UD |
286 | { |
287 | /* We would have to include <limits.h> to get a definition of MB_LEN_MAX. | |
288 | But this would only disturb the namespace. So we define our own | |
289 | version here. */ | |
290 | #define __WCHAR_MB_LEN_MAX 16 | |
291 | #if defined MB_LEN_MAX && MB_LEN_MAX != __WCHAR_MB_LEN_MAX | |
292 | # error "Assumed value of MB_LEN_MAX wrong" | |
293 | #endif | |
294 | if (__bos (__s) != (size_t) -1 && __WCHAR_MB_LEN_MAX > __bos (__s)) | |
295 | return __wcrtomb_chk (__s, __wchar, __ps, __bos (__s)); | |
296 | return __wcrtomb_alias (__s, __wchar, __ps); | |
297 | } | |
298 | ||
299 | ||
300 | extern size_t __mbsrtowcs_chk (wchar_t *__restrict __dst, | |
301 | __const char **__restrict __src, | |
302 | size_t __len, mbstate_t *__restrict __ps, | |
303 | size_t __dstlen) __THROW; | |
304 | extern size_t __REDIRECT_NTH (__mbsrtowcs_alias, | |
305 | (wchar_t *__restrict __dst, | |
306 | __const char **__restrict __src, | |
307 | size_t __len, mbstate_t *__restrict __ps), | |
308 | mbsrtowcs); | |
309 | ||
b037a293 | 310 | __extern_always_inline size_t |
dc4bb1c2 UD |
311 | __NTH (mbsrtowcs (wchar_t *__restrict __dst, __const char **__restrict __src, |
312 | size_t __len, mbstate_t *__restrict __ps)) | |
df6f8969 UD |
313 | { |
314 | if (__bos (__dst) != (size_t) -1 | |
315 | && (!__builtin_constant_p (__len) | |
f9a906e7 UD |
316 | || __len > __bos (__dst) / sizeof (wchar_t))) |
317 | return __mbsrtowcs_chk (__dst, __src, __len, __ps, | |
318 | __bos (__dst) / sizeof (wchar_t)); | |
df6f8969 UD |
319 | return __mbsrtowcs_alias (__dst, __src, __len, __ps); |
320 | } | |
321 | ||
322 | ||
323 | extern size_t __wcsrtombs_chk (char *__restrict __dst, | |
324 | __const wchar_t **__restrict __src, | |
325 | size_t __len, mbstate_t *__restrict __ps, | |
326 | size_t __dstlen) __THROW; | |
327 | extern size_t __REDIRECT_NTH (__wcsrtombs_alias, | |
328 | (char *__restrict __dst, | |
329 | __const wchar_t **__restrict __src, | |
330 | size_t __len, mbstate_t *__restrict __ps), | |
331 | wcsrtombs); | |
332 | ||
b037a293 | 333 | __extern_always_inline size_t |
dc4bb1c2 UD |
334 | __NTH (wcsrtombs (char *__restrict __dst, __const wchar_t **__restrict __src, |
335 | size_t __len, mbstate_t *__restrict __ps)) | |
df6f8969 UD |
336 | { |
337 | if (__bos (__dst) != (size_t) -1 | |
338 | && (!__builtin_constant_p (__len) || __len > __bos (__dst))) | |
339 | return __wcsrtombs_chk (__dst, __src, __len, __ps, __bos (__dst)); | |
340 | return __wcsrtombs_alias (__dst, __src, __len, __ps); | |
341 | } | |
342 | ||
343 | ||
344 | #ifdef __USE_GNU | |
345 | extern size_t __mbsnrtowcs_chk (wchar_t *__restrict __dst, | |
346 | __const char **__restrict __src, size_t __nmc, | |
347 | size_t __len, mbstate_t *__restrict __ps, | |
348 | size_t __dstlen) __THROW; | |
349 | extern size_t __REDIRECT_NTH (__mbsnrtowcs_alias, | |
350 | (wchar_t *__restrict __dst, | |
351 | __const char **__restrict __src, size_t __nmc, | |
352 | size_t __len, mbstate_t *__restrict __ps), | |
353 | mbsnrtowcs); | |
354 | ||
b037a293 | 355 | __extern_always_inline size_t |
dc4bb1c2 UD |
356 | __NTH (mbsnrtowcs (wchar_t *__restrict __dst, __const char **__restrict __src, |
357 | size_t __nmc, size_t __len, mbstate_t *__restrict __ps)) | |
df6f8969 UD |
358 | { |
359 | if (__bos (__dst) != (size_t) -1 | |
360 | && (!__builtin_constant_p (__len) | |
f9a906e7 UD |
361 | || __len > __bos (__dst) / sizeof (wchar_t))) |
362 | return __mbsnrtowcs_chk (__dst, __src, __nmc, __len, __ps, | |
363 | __bos (__dst) / sizeof (wchar_t)); | |
df6f8969 UD |
364 | return __mbsnrtowcs_alias (__dst, __src, __nmc, __len, __ps); |
365 | } | |
366 | ||
367 | ||
368 | extern size_t __wcsnrtombs_chk (char *__restrict __dst, | |
369 | __const wchar_t **__restrict __src, | |
370 | size_t __nwc, size_t __len, | |
371 | mbstate_t *__restrict __ps, size_t __dstlen) | |
372 | __THROW; | |
373 | extern size_t __REDIRECT_NTH (__wcsnrtombs_alias, | |
374 | (char *__restrict __dst, | |
375 | __const wchar_t **__restrict __src, | |
376 | size_t __nwc, size_t __len, | |
377 | mbstate_t *__restrict __ps), wcsnrtombs); | |
378 | ||
b037a293 | 379 | __extern_always_inline size_t |
dc4bb1c2 UD |
380 | __NTH (wcsnrtombs (char *__restrict __dst, __const wchar_t **__restrict __src, |
381 | size_t __nwc, size_t __len, mbstate_t *__restrict __ps)) | |
df6f8969 UD |
382 | { |
383 | if (__bos (__dst) != (size_t) -1 | |
384 | && (!__builtin_constant_p (__len) || __len > __bos (__dst))) | |
385 | return __wcsnrtombs_chk (__dst, __src, __nwc, __len, __ps, __bos (__dst)); | |
386 | return __wcsnrtombs_alias (__dst, __src, __nwc, __len, __ps); | |
387 | } | |
388 | #endif |