MIPS: Regenerate ulps
[glibc.git] / string / bits / string_fortified.h
blob5c93dd677d585a9c65b2562949a04068febe9bcc
1 /* Copyright (C) 2004-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #ifndef _BITS_STRING_FORTIFIED_H
19 #define _BITS_STRING_FORTIFIED_H 1
21 #ifndef _STRING_H
22 # error "Never use <bits/string_fortified.h> directly; include <string.h> instead."
23 #endif
25 __fortify_function void *
26 __NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
27 size_t __len))
29 return __builtin___memcpy_chk (__dest, __src, __len,
30 __glibc_objsize0 (__dest));
33 __fortify_function void *
34 __NTH (memmove (void *__dest, const void *__src, size_t __len))
36 return __builtin___memmove_chk (__dest, __src, __len,
37 __glibc_objsize0 (__dest));
40 #ifdef __USE_GNU
41 __fortify_function void *
42 __NTH (mempcpy (void *__restrict __dest, const void *__restrict __src,
43 size_t __len))
45 return __builtin___mempcpy_chk (__dest, __src, __len,
46 __glibc_objsize0 (__dest));
48 #endif
51 /* The first two tests here help to catch a somewhat common problem
52 where the second and third parameter are transposed. This is
53 especially problematic if the intended fill value is zero. In this
54 case no work is done at all. We detect these problems by referring
55 non-existing functions. */
56 __fortify_function void *
57 __NTH (memset (void *__dest, int __ch, size_t __len))
59 return __builtin___memset_chk (__dest, __ch, __len,
60 __glibc_objsize0 (__dest));
63 #ifdef __USE_MISC
64 # include <bits/strings_fortified.h>
66 void __explicit_bzero_chk (void *__dest, size_t __len, size_t __destlen)
67 __THROW __nonnull ((1)) __fortified_attr_access (__write_only__, 1, 2);
69 __fortify_function void
70 __NTH (explicit_bzero (void *__dest, size_t __len))
72 __explicit_bzero_chk (__dest, __len, __glibc_objsize0 (__dest));
74 #endif
76 __fortify_function __attribute_overloadable__ char *
77 __NTH (strcpy (__fortify_clang_overload_arg (char *, __restrict, __dest),
78 const char *__restrict __src))
79 __fortify_clang_warn_if_src_too_large (__dest, __src)
81 return __builtin___strcpy_chk (__dest, __src, __glibc_objsize (__dest));
84 #ifdef __USE_XOPEN2K8
85 __fortify_function __attribute_overloadable__ char *
86 __NTH (stpcpy (__fortify_clang_overload_arg (char *, __restrict, __dest),
87 const char *__restrict __src))
88 __fortify_clang_warn_if_src_too_large (__dest, __src)
90 return __builtin___stpcpy_chk (__dest, __src, __glibc_objsize (__dest));
92 #endif
95 __fortify_function __attribute_overloadable__ char *
96 __NTH (strncpy (__fortify_clang_overload_arg (char *, __restrict, __dest),
97 const char *__restrict __src, size_t __len))
98 __fortify_clang_warn_if_dest_too_small (__dest, __len)
100 return __builtin___strncpy_chk (__dest, __src, __len,
101 __glibc_objsize (__dest));
104 #ifdef __USE_XOPEN2K8
105 # if __GNUC_PREREQ (4, 7) || __glibc_clang_prereq (2, 6)
106 __fortify_function __attribute_overloadable__ char *
107 __NTH (stpncpy (__fortify_clang_overload_arg (char *, ,__dest),
108 const char *__src, size_t __n))
109 __fortify_clang_warn_if_dest_too_small (__dest, __n)
111 return __builtin___stpncpy_chk (__dest, __src, __n,
112 __glibc_objsize (__dest));
114 # else
115 extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
116 size_t __destlen) __THROW
117 __fortified_attr_access (__write_only__, 1, 3)
118 __attr_access ((__read_only__, 2));
119 extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
120 size_t __n), stpncpy);
122 __fortify_function __attribute_overloadable__ char *
123 __NTH (stpncpy (__fortify_clang_overload_arg (char *, ,__dest),
124 const char *__src, size_t __n))
126 if (__bos (__dest) != (size_t) -1
127 && (!__builtin_constant_p (__n) || __n > __bos (__dest)))
128 return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
129 return __stpncpy_alias (__dest, __src, __n);
131 # endif
132 #endif
135 __fortify_function __attribute_overloadable__ char *
136 __NTH (strcat (__fortify_clang_overload_arg (char *, __restrict, __dest),
137 const char *__restrict __src))
138 __fortify_clang_warn_if_src_too_large (__dest, __src)
140 return __builtin___strcat_chk (__dest, __src, __glibc_objsize (__dest));
144 __fortify_function __attribute_overloadable__ char *
145 __NTH (strncat (__fortify_clang_overload_arg (char *, __restrict, __dest),
146 const char *__restrict __src, size_t __len))
147 __fortify_clang_warn_if_src_too_large (__dest, __src)
149 return __builtin___strncat_chk (__dest, __src, __len,
150 __glibc_objsize (__dest));
153 #ifdef __USE_MISC
154 extern size_t __strlcpy_chk (char *__dest, const char *__src, size_t __n,
155 size_t __destlen) __THROW;
156 extern size_t __REDIRECT_NTH (__strlcpy_alias,
157 (char *__dest, const char *__src, size_t __n),
158 strlcpy);
160 __fortify_function __attribute_overloadable__ size_t
161 __NTH (strlcpy (__fortify_clang_overload_arg (char *, __restrict, __dest),
162 const char *__restrict __src, size_t __n))
163 __fortify_clang_warn_if_dest_too_small (__dest, __n)
165 if (__glibc_objsize (__dest) != (size_t) -1
166 && (!__builtin_constant_p (__n > __glibc_objsize (__dest))
167 || __n > __glibc_objsize (__dest)))
168 return __strlcpy_chk (__dest, __src, __n, __glibc_objsize (__dest));
169 return __strlcpy_alias (__dest, __src, __n);
172 extern size_t __strlcat_chk (char *__dest, const char *__src, size_t __n,
173 size_t __destlen) __THROW;
174 extern size_t __REDIRECT_NTH (__strlcat_alias,
175 (char *__dest, const char *__src, size_t __n),
176 strlcat);
178 __fortify_function __attribute_overloadable__ size_t
179 __NTH (strlcat (__fortify_clang_overload_arg (char *, __restrict, __dest),
180 const char *__restrict __src, size_t __n))
182 if (__glibc_objsize (__dest) != (size_t) -1
183 && (!__builtin_constant_p (__n > __glibc_objsize (__dest))
184 || __n > __glibc_objsize (__dest)))
185 return __strlcat_chk (__dest, __src, __n, __glibc_objsize (__dest));
186 return __strlcat_alias (__dest, __src, __n);
188 #endif /* __USE_MISC */
190 #endif /* bits/string_fortified.h */