]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdlib/bits/stdlib.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / stdlib / bits / stdlib.h
CommitLineData
b799f91d 1/* Checking macros for stdlib functions.
dff8da6b 2 Copyright (C) 2005-2024 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 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 38{
a643f60c
SP
39 size_t sz = __glibc_objsize (__resolved);
40
41 if (sz == (size_t) -1)
42 return __realpath_alias (__name, __resolved);
43
d6cd6bf4 44#if defined _LIBC_LIMITS_H_ && defined PATH_MAX
2bbd07c7 45 if (__glibc_unsafe_len (PATH_MAX, sizeof (char), sz))
a643f60c 46 return __realpath_chk_warn (__name, __resolved, sz);
d6cd6bf4 47#endif
a643f60c 48 return __realpath_chk (__name, __resolved, sz);
b799f91d
UD
49}
50
51
52extern int __ptsname_r_chk (int __fd, char *__buf, size_t __buflen,
06febd8c
MS
53 size_t __nreal) __THROW __nonnull ((2))
54 __attr_access ((__write_only__, 2, 3));
5c08f24c
UD
55extern int __REDIRECT_NTH (__ptsname_r_alias, (int __fd, char *__buf,
56 size_t __buflen), ptsname_r)
06febd8c 57 __nonnull ((2)) __attr_access ((__write_only__, 2, 3));
d6cd6bf4
UD
58extern int __REDIRECT_NTH (__ptsname_r_chk_warn,
59 (int __fd, char *__buf, size_t __buflen,
60 size_t __nreal), __ptsname_r_chk)
61 __nonnull ((2)) __warnattr ("ptsname_r called with buflen bigger than "
62 "size of buf");
b799f91d 63
5ac3ea17 64__fortify_function int
dc4bb1c2 65__NTH (ptsname_r (int __fd, char *__buf, size_t __buflen))
b799f91d 66{
a643f60c
SP
67 return __glibc_fortify (ptsname_r, __buflen, sizeof (char),
68 __glibc_objsize (__buf),
69 __fd, __buf, __buflen);
b799f91d
UD
70}
71
72
73extern int __wctomb_chk (char *__s, wchar_t __wchar, size_t __buflen)
74 __THROW __wur;
0396de51
UD
75extern int __REDIRECT_NTH (__wctomb_alias, (char *__s, wchar_t __wchar),
76 wctomb) __wur;
b799f91d 77
5ac3ea17 78__fortify_function __wur int
dc4bb1c2 79__NTH (wctomb (char *__s, wchar_t __wchar))
b799f91d
UD
80{
81 /* We would have to include <limits.h> to get a definition of MB_LEN_MAX.
82 But this would only disturb the namespace. So we define our own
83 version here. */
84#define __STDLIB_MB_LEN_MAX 16
85#if defined MB_LEN_MAX && MB_LEN_MAX != __STDLIB_MB_LEN_MAX
86# error "Assumed value of MB_LEN_MAX wrong"
87#endif
f9de8bfe
SP
88 if (__glibc_objsize (__s) != (size_t) -1
89 && __STDLIB_MB_LEN_MAX > __glibc_objsize (__s))
90 return __wctomb_chk (__s, __wchar, __glibc_objsize (__s));
b799f91d
UD
91 return __wctomb_alias (__s, __wchar);
92}
02ca3541
UD
93
94
95extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,
a784e502 96 const char *__restrict __src,
06febd8c
MS
97 size_t __len, size_t __dstlen) __THROW
98 __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
220b83d8 99extern size_t __REDIRECT_NTH (__mbstowcs_nulldst,
464d189b
NG
100 (wchar_t *__restrict __dst,
101 const char *__restrict __src,
220b83d8 102 size_t __len), mbstowcs)
464d189b 103 __attr_access ((__read_only__, 2));
02ca3541
UD
104extern size_t __REDIRECT_NTH (__mbstowcs_alias,
105 (wchar_t *__restrict __dst,
a784e502 106 const char *__restrict __src,
06febd8c
MS
107 size_t __len), mbstowcs)
108 __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
d6cd6bf4
UD
109extern size_t __REDIRECT_NTH (__mbstowcs_chk_warn,
110 (wchar_t *__restrict __dst,
a784e502 111 const char *__restrict __src,
d6cd6bf4
UD
112 size_t __len, size_t __dstlen), __mbstowcs_chk)
113 __warnattr ("mbstowcs called with dst buffer smaller than len "
114 "* sizeof (wchar_t)");
02ca3541 115
220b83d8 116__fortify_function size_t
a784e502 117__NTH (mbstowcs (wchar_t *__restrict __dst, const char *__restrict __src,
dc4bb1c2 118 size_t __len))
02ca3541 119{
464d189b 120 if (__builtin_constant_p (__dst == NULL) && __dst == NULL)
220b83d8 121 return __mbstowcs_nulldst (__dst, __src, __len);
464d189b
NG
122 else
123 return __glibc_fortify_n (mbstowcs, __len, sizeof (wchar_t),
124 __glibc_objsize (__dst), __dst, __src, __len);
02ca3541
UD
125}
126
02ca3541 127extern size_t __wcstombs_chk (char *__restrict __dst,
a784e502 128 const wchar_t *__restrict __src,
06febd8c
MS
129 size_t __len, size_t __dstlen) __THROW
130 __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
02ca3541
UD
131extern size_t __REDIRECT_NTH (__wcstombs_alias,
132 (char *__restrict __dst,
a784e502 133 const wchar_t *__restrict __src,
06febd8c
MS
134 size_t __len), wcstombs)
135 __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
d6cd6bf4
UD
136extern size_t __REDIRECT_NTH (__wcstombs_chk_warn,
137 (char *__restrict __dst,
a784e502 138 const wchar_t *__restrict __src,
d6cd6bf4
UD
139 size_t __len, size_t __dstlen), __wcstombs_chk)
140 __warnattr ("wcstombs called with dst buffer smaller than len");
02ca3541 141
5ac3ea17 142__fortify_function size_t
a784e502 143__NTH (wcstombs (char *__restrict __dst, const wchar_t *__restrict __src,
dc4bb1c2 144 size_t __len))
02ca3541 145{
a643f60c
SP
146 return __glibc_fortify (wcstombs, __len, sizeof (char),
147 __glibc_objsize (__dst),
148 __dst, __src, __len);
02ca3541 149}