]>
Commit | Line | Data |
---|---|---|
6d7e8eda | 1 | /* Copyright (C) 1991-2023 Free Software Foundation, Inc. |
ba1ffaa1 | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
ba1ffaa1 | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 8 | |
ba1ffaa1 UD |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
28f540f4 RM |
17 | |
18 | /* | |
d1646309 | 19 | * ISO C99 Standard: 7.21 String handling <string.h> |
28f540f4 RM |
20 | */ |
21 | ||
22 | #ifndef _STRING_H | |
28f540f4 | 23 | #define _STRING_H 1 |
5107cf1d | 24 | |
48789000 JM |
25 | #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION |
26 | #include <bits/libc-header-start.h> | |
28f540f4 RM |
27 | |
28 | __BEGIN_DECLS | |
29 | ||
30 | /* Get size_t and NULL from <stddef.h>. */ | |
31 | #define __need_size_t | |
32 | #define __need_NULL | |
33 | #include <stddef.h> | |
34 | ||
8e2e833a | 35 | /* Tell the caller that we provide correct C++ prototypes. */ |
953ceff1 KK |
36 | #if defined __cplusplus && (__GNUC_PREREQ (4, 4) \ |
37 | || __glibc_clang_prereq (3, 5)) | |
d8387c7b UD |
38 | # define __CORRECT_ISO_CPP_STRING_H_PROTO |
39 | #endif | |
40 | ||
28f540f4 RM |
41 | |
42 | /* Copy N bytes of SRC to DEST. */ | |
a784e502 UD |
43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src, |
44 | size_t __n) __THROW __nonnull ((1, 2)); | |
28f540f4 RM |
45 | /* Copy N bytes of SRC to DEST, guaranteeing |
46 | correct behavior for overlapping strings. */ | |
a784e502 | 47 | extern void *memmove (void *__dest, const void *__src, size_t __n) |
be27d08c | 48 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
49 | |
50 | /* Copy no more than N bytes of SRC to DEST, stopping when C is found. | |
51 | Return the position in DEST one byte past where C was copied, | |
52 | or NULL if C was not found in the first N bytes of SRC. */ | |
a8c2fa98 | 53 | #if defined __USE_MISC || defined __USE_XOPEN || __GLIBC_USE (ISOC2X) |
a784e502 | 54 | extern void *memccpy (void *__restrict __dest, const void *__restrict __src, |
98cbe360 | 55 | int __c, size_t __n) |
06febd8c | 56 | __THROW __nonnull ((1, 2)) __attr_access ((__write_only__, 1, 4)); |
acd7f096 | 57 | #endif /* Misc || X/Open. */ |
28f540f4 RM |
58 | |
59 | ||
60 | /* Set N bytes of S to C. */ | |
be27d08c | 61 | extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1)); |
28f540f4 RM |
62 | |
63 | /* Compare N bytes of S1 and S2. */ | |
a784e502 | 64 | extern int memcmp (const void *__s1, const void *__s2, size_t __n) |
be27d08c | 65 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
44829b3d NG |
66 | |
67 | /* Compare N bytes of S1 and S2. Return zero if S1 and S2 are equal. | |
68 | Return some non-zero value otherwise. | |
69 | ||
70 | Essentially __memcmpeq has the exact same semantics as memcmp | |
71 | except the return value is less constrained. memcmp is always a | |
72 | correct implementation of __memcmpeq. As well !!memcmp, -memcmp, | |
73 | or bcmp are correct implementations. | |
74 | ||
75 | __memcmpeq is meant to be used by compilers when memcmp return is | |
3c23fa9f | 76 | only used for its boolean value. |
44829b3d NG |
77 | |
78 | __memcmpeq is declared only for use by compilers. Programs should | |
79 | continue to use memcmp. */ | |
80 | extern int __memcmpeq (const void *__s1, const void *__s2, size_t __n) | |
81 | __THROW __attribute_pure__ __nonnull ((1, 2)); | |
28f540f4 RM |
82 | |
83 | /* Search N bytes of S for C. */ | |
d8387c7b | 84 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
85 | extern "C++" |
86 | { | |
87 | extern void *memchr (void *__s, int __c, size_t __n) | |
d8387c7b | 88 | __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1)); |
a784e502 | 89 | extern const void *memchr (const void *__s, int __c, size_t __n) |
d8387c7b | 90 | __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1)); |
8585cb74 UD |
91 | |
92 | # ifdef __OPTIMIZE__ | |
93 | __extern_always_inline void * | |
94 | memchr (void *__s, int __c, size_t __n) __THROW | |
95 | { | |
96 | return __builtin_memchr (__s, __c, __n); | |
97 | } | |
98 | ||
a784e502 UD |
99 | __extern_always_inline const void * |
100 | memchr (const void *__s, int __c, size_t __n) __THROW | |
8585cb74 UD |
101 | { |
102 | return __builtin_memchr (__s, __c, __n); | |
103 | } | |
104 | # endif | |
105 | } | |
d8387c7b | 106 | #else |
a784e502 | 107 | extern void *memchr (const void *__s, int __c, size_t __n) |
be27d08c | 108 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 109 | #endif |
28f540f4 | 110 | |
482eec0d UD |
111 | #ifdef __USE_GNU |
112 | /* Search in S for C. This is similar to `memchr' but there is no | |
113 | length limit. */ | |
d8387c7b UD |
114 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
115 | extern "C++" void *rawmemchr (void *__s, int __c) | |
116 | __THROW __asm ("rawmemchr") __attribute_pure__ __nonnull ((1)); | |
a784e502 | 117 | extern "C++" const void *rawmemchr (const void *__s, int __c) |
d8387c7b UD |
118 | __THROW __asm ("rawmemchr") __attribute_pure__ __nonnull ((1)); |
119 | # else | |
a784e502 | 120 | extern void *rawmemchr (const void *__s, int __c) |
be27d08c | 121 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 122 | # endif |
ca747856 RM |
123 | |
124 | /* Search N bytes of S for the final occurrence of C. */ | |
d8387c7b UD |
125 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
126 | extern "C++" void *memrchr (void *__s, int __c, size_t __n) | |
06febd8c MS |
127 | __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1)) |
128 | __attr_access ((__read_only__, 1, 3)); | |
a784e502 | 129 | extern "C++" const void *memrchr (const void *__s, int __c, size_t __n) |
06febd8c MS |
130 | __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1)) |
131 | __attr_access ((__read_only__, 1, 3)); | |
d8387c7b | 132 | # else |
a784e502 | 133 | extern void *memrchr (const void *__s, int __c, size_t __n) |
06febd8c MS |
134 | __THROW __attribute_pure__ __nonnull ((1)) |
135 | __attr_access ((__read_only__, 1, 3)); | |
d8387c7b | 136 | # endif |
482eec0d UD |
137 | #endif |
138 | ||
28f540f4 RM |
139 | |
140 | /* Copy SRC to DEST. */ | |
a784e502 | 141 | extern char *strcpy (char *__restrict __dest, const char *__restrict __src) |
be27d08c | 142 | __THROW __nonnull ((1, 2)); |
28f540f4 | 143 | /* Copy no more than N characters of SRC to DEST. */ |
c1422e5b | 144 | extern char *strncpy (char *__restrict __dest, |
a784e502 | 145 | const char *__restrict __src, size_t __n) |
be27d08c | 146 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
147 | |
148 | /* Append SRC onto DEST. */ | |
a784e502 | 149 | extern char *strcat (char *__restrict __dest, const char *__restrict __src) |
be27d08c | 150 | __THROW __nonnull ((1, 2)); |
28f540f4 | 151 | /* Append no more than N characters from SRC onto DEST. */ |
a784e502 | 152 | extern char *strncat (char *__restrict __dest, const char *__restrict __src, |
be27d08c | 153 | size_t __n) __THROW __nonnull ((1, 2)); |
28f540f4 RM |
154 | |
155 | /* Compare S1 and S2. */ | |
a784e502 | 156 | extern int strcmp (const char *__s1, const char *__s2) |
be27d08c | 157 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 | 158 | /* Compare N characters of S1 and S2. */ |
a784e502 | 159 | extern int strncmp (const char *__s1, const char *__s2, size_t __n) |
be27d08c | 160 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 RM |
161 | |
162 | /* Compare the collated forms of S1 and S2. */ | |
a784e502 | 163 | extern int strcoll (const char *__s1, const char *__s2) |
be27d08c | 164 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 | 165 | /* Put a transformation of SRC into no more than N bytes of DEST. */ |
c1422e5b | 166 | extern size_t strxfrm (char *__restrict __dest, |
a784e502 | 167 | const char *__restrict __src, size_t __n) |
06febd8c | 168 | __THROW __nonnull ((2)) __attr_access ((__write_only__, 1, 3)); |
28f540f4 | 169 | |
6cbe890a | 170 | #ifdef __USE_XOPEN2K8 |
f0be25b6 ZW |
171 | /* POSIX.1-2008 extended locale interface (see locale.h). */ |
172 | # include <bits/types/locale_t.h> | |
c84142e8 | 173 | |
7773556d | 174 | /* Compare the collated forms of S1 and S2, using sorting rules from L. */ |
af85385f | 175 | extern int strcoll_l (const char *__s1, const char *__s2, locale_t __l) |
be27d08c | 176 | __THROW __attribute_pure__ __nonnull ((1, 2, 3)); |
7773556d ZW |
177 | /* Put a transformation of SRC into no more than N bytes of DEST, |
178 | using sorting rules from L. */ | |
a784e502 | 179 | extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n, |
06febd8c MS |
180 | locale_t __l) __THROW __nonnull ((2, 4)) |
181 | __attr_access ((__write_only__, 1, 3)); | |
c84142e8 UD |
182 | #endif |
183 | ||
48789000 | 184 | #if (defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 \ |
a8c2fa98 | 185 | || __GLIBC_USE (LIB_EXT2) || __GLIBC_USE (ISOC2X)) |
28f540f4 | 186 | /* Duplicate S, returning an identical malloc'd string. */ |
a784e502 | 187 | extern char *strdup (const char *__s) |
be27d08c | 188 | __THROW __attribute_malloc__ __nonnull ((1)); |
28f540f4 RM |
189 | #endif |
190 | ||
6dbe2837 RM |
191 | /* Return a malloc'd copy of at most N bytes of STRING. The |
192 | resultant string is terminated even if no null terminator | |
193 | appears before STRING[N]. */ | |
a8c2fa98 | 194 | #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2) || __GLIBC_USE (ISOC2X) |
a784e502 | 195 | extern char *strndup (const char *__string, size_t __n) |
be27d08c | 196 | __THROW __attribute_malloc__ __nonnull ((1)); |
6d52618b | 197 | #endif |
6dbe2837 | 198 | |
377a515b | 199 | #if defined __USE_GNU && defined __GNUC__ |
036cc82f | 200 | /* Duplicate S, returning an identical alloca'd string. */ |
3996f34b | 201 | # define strdupa(s) \ |
036cc82f RM |
202 | (__extension__ \ |
203 | ({ \ | |
a784e502 | 204 | const char *__old = (s); \ |
036cc82f | 205 | size_t __len = strlen (__old) + 1; \ |
8c8f3704 | 206 | char *__new = (char *) __builtin_alloca (__len); \ |
3996f34b | 207 | (char *) memcpy (__new, __old, __len); \ |
036cc82f RM |
208 | })) |
209 | ||
6dbe2837 | 210 | /* Return an alloca'd copy of at most N bytes of string. */ |
3996f34b | 211 | # define strndupa(s, n) \ |
036cc82f RM |
212 | (__extension__ \ |
213 | ({ \ | |
a784e502 | 214 | const char *__old = (s); \ |
036cc82f | 215 | size_t __len = strnlen (__old, (n)); \ |
8c8f3704 | 216 | char *__new = (char *) __builtin_alloca (__len + 1); \ |
036cc82f | 217 | __new[__len] = '\0'; \ |
3996f34b | 218 | (char *) memcpy (__new, __old, __len); \ |
036cc82f | 219 | })) |
02ac66c5 RM |
220 | #endif |
221 | ||
28f540f4 | 222 | /* Find the first occurrence of C in S. */ |
d8387c7b | 223 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
224 | extern "C++" |
225 | { | |
226 | extern char *strchr (char *__s, int __c) | |
d8387c7b | 227 | __THROW __asm ("strchr") __attribute_pure__ __nonnull ((1)); |
a784e502 | 228 | extern const char *strchr (const char *__s, int __c) |
d8387c7b | 229 | __THROW __asm ("strchr") __attribute_pure__ __nonnull ((1)); |
8585cb74 UD |
230 | |
231 | # ifdef __OPTIMIZE__ | |
232 | __extern_always_inline char * | |
233 | strchr (char *__s, int __c) __THROW | |
234 | { | |
235 | return __builtin_strchr (__s, __c); | |
236 | } | |
237 | ||
a784e502 UD |
238 | __extern_always_inline const char * |
239 | strchr (const char *__s, int __c) __THROW | |
8585cb74 UD |
240 | { |
241 | return __builtin_strchr (__s, __c); | |
242 | } | |
243 | # endif | |
244 | } | |
d8387c7b | 245 | #else |
a784e502 | 246 | extern char *strchr (const char *__s, int __c) |
be27d08c | 247 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 248 | #endif |
28f540f4 | 249 | /* Find the last occurrence of C in S. */ |
d8387c7b | 250 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
251 | extern "C++" |
252 | { | |
253 | extern char *strrchr (char *__s, int __c) | |
d8387c7b | 254 | __THROW __asm ("strrchr") __attribute_pure__ __nonnull ((1)); |
a784e502 | 255 | extern const char *strrchr (const char *__s, int __c) |
d8387c7b | 256 | __THROW __asm ("strrchr") __attribute_pure__ __nonnull ((1)); |
8585cb74 UD |
257 | |
258 | # ifdef __OPTIMIZE__ | |
259 | __extern_always_inline char * | |
260 | strrchr (char *__s, int __c) __THROW | |
261 | { | |
262 | return __builtin_strrchr (__s, __c); | |
263 | } | |
264 | ||
a784e502 UD |
265 | __extern_always_inline const char * |
266 | strrchr (const char *__s, int __c) __THROW | |
8585cb74 UD |
267 | { |
268 | return __builtin_strrchr (__s, __c); | |
269 | } | |
270 | # endif | |
271 | } | |
d8387c7b | 272 | #else |
a784e502 | 273 | extern char *strrchr (const char *__s, int __c) |
be27d08c | 274 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 275 | #endif |
28f540f4 | 276 | |
c4563d2d | 277 | #ifdef __USE_GNU |
557a9213 | 278 | /* This function is similar to `strchr'. But it returns a pointer to |
c4563d2d | 279 | the closing NUL byte in case C is not found in S. */ |
d8387c7b UD |
280 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
281 | extern "C++" char *strchrnul (char *__s, int __c) | |
282 | __THROW __asm ("strchrnul") __attribute_pure__ __nonnull ((1)); | |
a784e502 | 283 | extern "C++" const char *strchrnul (const char *__s, int __c) |
d8387c7b UD |
284 | __THROW __asm ("strchrnul") __attribute_pure__ __nonnull ((1)); |
285 | # else | |
a784e502 | 286 | extern char *strchrnul (const char *__s, int __c) |
be27d08c | 287 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 288 | # endif |
c4563d2d UD |
289 | #endif |
290 | ||
28f540f4 RM |
291 | /* Return the length of the initial segment of S which |
292 | consists entirely of characters not in REJECT. */ | |
a784e502 | 293 | extern size_t strcspn (const char *__s, const char *__reject) |
be27d08c | 294 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 RM |
295 | /* Return the length of the initial segment of S which |
296 | consists entirely of characters in ACCEPT. */ | |
a784e502 | 297 | extern size_t strspn (const char *__s, const char *__accept) |
be27d08c | 298 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
6d52618b | 299 | /* Find the first occurrence in S of any character in ACCEPT. */ |
d8387c7b | 300 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
301 | extern "C++" |
302 | { | |
a784e502 | 303 | extern char *strpbrk (char *__s, const char *__accept) |
d8387c7b | 304 | __THROW __asm ("strpbrk") __attribute_pure__ __nonnull ((1, 2)); |
a784e502 | 305 | extern const char *strpbrk (const char *__s, const char *__accept) |
d8387c7b | 306 | __THROW __asm ("strpbrk") __attribute_pure__ __nonnull ((1, 2)); |
8585cb74 UD |
307 | |
308 | # ifdef __OPTIMIZE__ | |
309 | __extern_always_inline char * | |
a784e502 | 310 | strpbrk (char *__s, const char *__accept) __THROW |
8585cb74 UD |
311 | { |
312 | return __builtin_strpbrk (__s, __accept); | |
313 | } | |
314 | ||
a784e502 UD |
315 | __extern_always_inline const char * |
316 | strpbrk (const char *__s, const char *__accept) __THROW | |
8585cb74 UD |
317 | { |
318 | return __builtin_strpbrk (__s, __accept); | |
319 | } | |
320 | # endif | |
321 | } | |
d8387c7b | 322 | #else |
a784e502 | 323 | extern char *strpbrk (const char *__s, const char *__accept) |
be27d08c | 324 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
d8387c7b | 325 | #endif |
6d52618b | 326 | /* Find the first occurrence of NEEDLE in HAYSTACK. */ |
d8387c7b | 327 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
328 | extern "C++" |
329 | { | |
a784e502 | 330 | extern char *strstr (char *__haystack, const char *__needle) |
d8387c7b | 331 | __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2)); |
a784e502 | 332 | extern const char *strstr (const char *__haystack, const char *__needle) |
d8387c7b | 333 | __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2)); |
8585cb74 UD |
334 | |
335 | # ifdef __OPTIMIZE__ | |
336 | __extern_always_inline char * | |
a784e502 | 337 | strstr (char *__haystack, const char *__needle) __THROW |
8585cb74 UD |
338 | { |
339 | return __builtin_strstr (__haystack, __needle); | |
340 | } | |
341 | ||
a784e502 UD |
342 | __extern_always_inline const char * |
343 | strstr (const char *__haystack, const char *__needle) __THROW | |
8585cb74 UD |
344 | { |
345 | return __builtin_strstr (__haystack, __needle); | |
346 | } | |
347 | # endif | |
348 | } | |
d8387c7b | 349 | #else |
a784e502 | 350 | extern char *strstr (const char *__haystack, const char *__needle) |
be27d08c | 351 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
d8387c7b | 352 | #endif |
f4017d20 | 353 | |
f4017d20 | 354 | |
28f540f4 | 355 | /* Divide S into tokens separated by characters in DELIM. */ |
a784e502 | 356 | extern char *strtok (char *__restrict __s, const char *__restrict __delim) |
be27d08c | 357 | __THROW __nonnull ((2)); |
28f540f4 | 358 | |
59dd8641 RM |
359 | /* Divide S into tokens separated by characters in DELIM. Information |
360 | passed between calls are stored in SAVE_PTR. */ | |
c1422e5b | 361 | extern char *__strtok_r (char *__restrict __s, |
a784e502 | 362 | const char *__restrict __delim, |
be27d08c UD |
363 | char **__restrict __save_ptr) |
364 | __THROW __nonnull ((2, 3)); | |
acd7f096 | 365 | #ifdef __USE_POSIX |
a784e502 | 366 | extern char *strtok_r (char *__restrict __s, const char *__restrict __delim, |
be27d08c UD |
367 | char **__restrict __save_ptr) |
368 | __THROW __nonnull ((2, 3)); | |
9d187dd4 | 369 | #endif |
59dd8641 | 370 | |
7a5affeb UD |
371 | #ifdef __USE_GNU |
372 | /* Similar to `strstr' but this function ignores the case of both strings. */ | |
d8387c7b | 373 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
a784e502 | 374 | extern "C++" char *strcasestr (char *__haystack, const char *__needle) |
d8387c7b | 375 | __THROW __asm ("strcasestr") __attribute_pure__ __nonnull ((1, 2)); |
a784e502 UD |
376 | extern "C++" const char *strcasestr (const char *__haystack, |
377 | const char *__needle) | |
d8387c7b UD |
378 | __THROW __asm ("strcasestr") __attribute_pure__ __nonnull ((1, 2)); |
379 | # else | |
a784e502 | 380 | extern char *strcasestr (const char *__haystack, const char *__needle) |
be27d08c | 381 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
d8387c7b | 382 | # endif |
7a5affeb UD |
383 | #endif |
384 | ||
9d187dd4 | 385 | #ifdef __USE_GNU |
6d52618b | 386 | /* Find the first occurrence of NEEDLE in HAYSTACK. |
28f540f4 RM |
387 | NEEDLE is NEEDLELEN bytes long; |
388 | HAYSTACK is HAYSTACKLEN bytes long. */ | |
a784e502 UD |
389 | extern void *memmem (const void *__haystack, size_t __haystacklen, |
390 | const void *__needle, size_t __needlelen) | |
06febd8c MS |
391 | __THROW __attribute_pure__ __nonnull ((1, 3)) |
392 | __attr_access ((__read_only__, 1, 2)) | |
393 | __attr_access ((__read_only__, 3, 4)); | |
9a0a462c UD |
394 | |
395 | /* Copy N bytes of SRC to DEST, return pointer to bytes after the | |
396 | last written byte. */ | |
c1422e5b | 397 | extern void *__mempcpy (void *__restrict __dest, |
a784e502 | 398 | const void *__restrict __src, size_t __n) |
be27d08c | 399 | __THROW __nonnull ((1, 2)); |
c1422e5b | 400 | extern void *mempcpy (void *__restrict __dest, |
a784e502 | 401 | const void *__restrict __src, size_t __n) |
be27d08c | 402 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
403 | #endif |
404 | ||
8d71c7b0 | 405 | |
28f540f4 | 406 | /* Return the length of S. */ |
a784e502 | 407 | extern size_t strlen (const char *__s) |
be27d08c | 408 | __THROW __attribute_pure__ __nonnull ((1)); |
28f540f4 | 409 | |
6cbe890a | 410 | #ifdef __USE_XOPEN2K8 |
8d71c7b0 RM |
411 | /* Find the length of STRING, but scan at most MAXLEN characters. |
412 | If no '\0' terminator is found in that many characters, return MAXLEN. */ | |
a784e502 | 413 | extern size_t strnlen (const char *__string, size_t __maxlen) |
be27d08c | 414 | __THROW __attribute_pure__ __nonnull ((1)); |
8d71c7b0 RM |
415 | #endif |
416 | ||
417 | ||
73299943 UD |
418 | /* Return a string describing the meaning of the `errno' code in ERRNUM. */ |
419 | extern char *strerror (int __errnum) __THROW; | |
acd7f096 | 420 | #ifdef __USE_XOPEN2K |
61645263 UD |
421 | /* Reentrant version of `strerror'. |
422 | There are 2 flavors of `strerror_r', GNU which returns the string | |
423 | and may or may not use the supplied temporary buffer and POSIX one | |
424 | which fills the string into the buffer. | |
425 | To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L | |
426 | without -D_GNU_SOURCE is needed, otherwise the GNU version is | |
427 | preferred. */ | |
428 | # if defined __USE_XOPEN2K && !defined __USE_GNU | |
429 | /* Fill BUF with a string describing the meaning of the `errno' code in | |
430 | ERRNUM. */ | |
f377d022 UD |
431 | # ifdef __REDIRECT_NTH |
432 | extern int __REDIRECT_NTH (strerror_r, | |
433 | (int __errnum, char *__buf, size_t __buflen), | |
06febd8c MS |
434 | __xpg_strerror_r) __nonnull ((2)) |
435 | __attr_access ((__write_only__, 2, 3)); | |
61645263 UD |
436 | # else |
437 | extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen) | |
06febd8c | 438 | __THROW __nonnull ((2)) __attr_access ((__write_only__, 2, 3)); |
61645263 UD |
439 | # define strerror_r __xpg_strerror_r |
440 | # endif | |
441 | # else | |
442 | /* If a temporary buffer is required, at most BUFLEN bytes of BUF will be | |
443 | used. */ | |
be27d08c | 444 | extern char *strerror_r (int __errnum, char *__buf, size_t __buflen) |
06febd8c | 445 | __THROW __nonnull ((2)) __wur __attr_access ((__write_only__, 2, 3)); |
61645263 | 446 | # endif |
325081b9 AZ |
447 | |
448 | # ifdef __USE_GNU | |
449 | /* Return a string describing the meaning of tthe error in ERR. */ | |
450 | extern const char *strerrordesc_np (int __err) __THROW; | |
451 | /* Return a string with the error name in ERR. */ | |
452 | extern const char *strerrorname_np (int __err) __THROW; | |
453 | # endif | |
60478656 | 454 | #endif |
28f540f4 | 455 | |
6cbe890a | 456 | #ifdef __USE_XOPEN2K8 |
4a44ce79 | 457 | /* Translate error number to string according to the locale L. */ |
af85385f | 458 | extern char *strerror_l (int __errnum, locale_t __l) __THROW; |
4a44ce79 UD |
459 | #endif |
460 | ||
498afc54 | 461 | #ifdef __USE_MISC |
7b037c09 | 462 | # include <strings.h> |
28f540f4 | 463 | |
7b037c09 | 464 | /* Set N bytes of S to 0. The compiler will not delete a call to this |
ea1bd74d | 465 | function, even if S is dead after the call. */ |
06febd8c | 466 | extern void explicit_bzero (void *__s, size_t __n) __THROW __nonnull ((1)) |
e938c027 | 467 | __fortified_attr_access (__write_only__, 1, 2); |
ea1bd74d | 468 | |
28f540f4 RM |
469 | /* Return the next DELIM-delimited token from *STRINGP, |
470 | terminating it with a '\0', and update *STRINGP to point past it. */ | |
c1422e5b | 471 | extern char *strsep (char **__restrict __stringp, |
a784e502 | 472 | const char *__restrict __delim) |
be27d08c | 473 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
474 | #endif |
475 | ||
6cbe890a | 476 | #ifdef __USE_XOPEN2K8 |
28f540f4 | 477 | /* Return a string describing the meaning of the signal number in SIG. */ |
c1422e5b | 478 | extern char *strsignal (int __sig) __THROW; |
28f540f4 | 479 | |
bfe05aa2 AZ |
480 | # ifdef __USE_GNU |
481 | /* Return an abbreviation string for the signal number SIG. */ | |
482 | extern const char *sigabbrev_np (int __sig) __THROW; | |
483 | /* Return a string describing the meaning of the signal number in SIG, | |
484 | the result is not translated. */ | |
485 | extern const char *sigdescr_np (int __sig) __THROW; | |
486 | # endif | |
487 | ||
28f540f4 | 488 | /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ |
a784e502 | 489 | extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src) |
be27d08c | 490 | __THROW __nonnull ((1, 2)); |
a784e502 | 491 | extern char *stpcpy (char *__restrict __dest, const char *__restrict __src) |
be27d08c | 492 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
493 | |
494 | /* Copy no more than N characters of SRC to DEST, returning the address of | |
495 | the last character written into DEST. */ | |
c1422e5b | 496 | extern char *__stpncpy (char *__restrict __dest, |
a784e502 | 497 | const char *__restrict __src, size_t __n) |
be27d08c | 498 | __THROW __nonnull ((1, 2)); |
c1422e5b | 499 | extern char *stpncpy (char *__restrict __dest, |
a784e502 | 500 | const char *__restrict __src, size_t __n) |
be27d08c | 501 | __THROW __nonnull ((1, 2)); |
6cbe890a UD |
502 | #endif |
503 | ||
504 | #ifdef __USE_GNU | |
505 | /* Compare S1 and S2 as strings holding name & indices/version numbers. */ | |
a784e502 | 506 | extern int strverscmp (const char *__s1, const char *__s2) |
6cbe890a | 507 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 | 508 | |
28f540f4 | 509 | /* Sautee STRING briskly. */ |
be27d08c | 510 | extern char *strfry (char *__string) __THROW __nonnull ((1)); |
28f540f4 RM |
511 | |
512 | /* Frobnicate N bytes of S. */ | |
06febd8c | 513 | extern void *memfrob (void *__s, size_t __n) __THROW __nonnull ((1)) |
2c6cabb3 | 514 | __attr_access ((__read_write__, 1, 2)); |
28f540f4 | 515 | |
92f1da4d | 516 | # ifndef basename |
dd33e89f UD |
517 | /* Return the file name within directory of FILENAME. We don't |
518 | declare the function if the `basename' macro is available (defined | |
519 | in <libgen.h>) which makes the XPG version of this function | |
520 | available. */ | |
d8387c7b UD |
521 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
522 | extern "C++" char *basename (char *__filename) | |
523 | __THROW __asm ("basename") __nonnull ((1)); | |
a784e502 | 524 | extern "C++" const char *basename (const char *__filename) |
d8387c7b UD |
525 | __THROW __asm ("basename") __nonnull ((1)); |
526 | # else | |
a784e502 | 527 | extern char *basename (const char *__filename) __THROW __nonnull ((1)); |
d8387c7b | 528 | # endif |
92f1da4d | 529 | # endif |
84724245 RM |
530 | #endif |
531 | ||
155bc2a5 | 532 | #if __GNUC_PREREQ (3,4) |
5ac3ea17 | 533 | # if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function |
b5cc329c | 534 | /* Functions with security checks. */ |
09a596cc | 535 | # include <bits/string_fortified.h> |
b5cc329c | 536 | # endif |
92f1da4d UD |
537 | #endif |
538 | ||
28f540f4 RM |
539 | __END_DECLS |
540 | ||
541 | #endif /* string.h */ |