]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdlib/bits/stdlib.h
[BZ #5058]
[thirdparty/glibc.git] / stdlib / bits / stdlib.h
CommitLineData
b799f91d 1/* Checking macros for stdlib functions.
b037a293 2 Copyright (C) 2005, 2007 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
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 _STDLIB_H
21# error "Never include <bits/stdlib.h> directly; use <stdlib.h> instead."
22#endif
23
24extern char *__realpath_chk (__const char *__restrict __name,
25 char *__restrict __resolved,
26 size_t __resolvedlen) __THROW __wur;
5c08f24c
UD
27extern char *__REDIRECT_NTH (__realpath_alias,
28 (__const char *__restrict __name,
29 char *__restrict __resolved), realpath) __wur;
b799f91d 30
b037a293 31__extern_always_inline __wur char *
dc4bb1c2 32__NTH (realpath (__const char *__restrict __name, char *__restrict __resolved))
b799f91d
UD
33{
34 if (__bos (__resolved) != (size_t) -1)
35 return __realpath_chk (__name, __resolved, __bos (__resolved));
36
37 return __realpath_alias (__name, __resolved);
38}
39
40
41extern int __ptsname_r_chk (int __fd, char *__buf, size_t __buflen,
42 size_t __nreal) __THROW __nonnull ((2));
5c08f24c
UD
43extern int __REDIRECT_NTH (__ptsname_r_alias, (int __fd, char *__buf,
44 size_t __buflen), ptsname_r)
45 __nonnull ((2));
b799f91d 46
b037a293 47__extern_always_inline int
dc4bb1c2 48__NTH (ptsname_r (int __fd, char *__buf, size_t __buflen))
b799f91d
UD
49{
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);
54}
55
56
57extern int __wctomb_chk (char *__s, wchar_t __wchar, size_t __buflen)
58 __THROW __wur;
0396de51
UD
59extern int __REDIRECT_NTH (__wctomb_alias, (char *__s, wchar_t __wchar),
60 wctomb) __wur;
b799f91d 61
b037a293 62__extern_always_inline __wur int
dc4bb1c2 63__NTH (wctomb (char *__s, wchar_t __wchar))
b799f91d
UD
64{
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);
75}
02ca3541
UD
76
77
78extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,
79 __const char *__restrict __src,
80 size_t __len, size_t __dstlen) __THROW;
81extern size_t __REDIRECT_NTH (__mbstowcs_alias,
82 (wchar_t *__restrict __dst,
83 __const char *__restrict __src,
84 size_t __len), mbstowcs);
85
b037a293 86__extern_always_inline size_t
dc4bb1c2
UD
87__NTH (mbstowcs (wchar_t *__restrict __dst, __const char *__restrict __src,
88 size_t __len))
02ca3541
UD
89{
90 if (__bos (__dst) != (size_t) -1
91 && (!__builtin_constant_p (__len)
f9a906e7
UD
92 || __len > __bos (__dst) / sizeof (wchar_t)))
93 return __mbstowcs_chk (__dst, __src, __len,
94 __bos (__dst) / sizeof (wchar_t));
02ca3541
UD
95 return __mbstowcs_alias (__dst, __src, __len);
96}
97
98
99extern size_t __wcstombs_chk (char *__restrict __dst,
100 __const wchar_t *__restrict __src,
101 size_t __len, size_t __dstlen) __THROW;
102extern size_t __REDIRECT_NTH (__wcstombs_alias,
103 (char *__restrict __dst,
104 __const wchar_t *__restrict __src,
105 size_t __len), wcstombs);
106
b037a293 107__extern_always_inline size_t
dc4bb1c2
UD
108__NTH (wcstombs (char *__restrict __dst, __const wchar_t *__restrict __src,
109 size_t __len))
02ca3541
UD
110{
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);
115}