]>
Commit | Line | Data |
---|---|---|
d4697bc9 | 1 | /* Copyright (C) 1991-2014 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 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://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 | |
28f540f4 RM |
25 | #include <features.h> |
26 | ||
27 | __BEGIN_DECLS | |
28 | ||
29 | /* Get size_t and NULL from <stddef.h>. */ | |
30 | #define __need_size_t | |
31 | #define __need_NULL | |
32 | #include <stddef.h> | |
33 | ||
3f637079 BM |
34 | /* Provide correct C++ prototypes, and indicate this to the caller. This |
35 | requires a compatible C++ standard library. As a heuristic, we provide | |
36 | these when the compiler indicates full conformance with C++98 or later, | |
37 | and for older GCC versions that are known to provide a compatible | |
38 | libstdc++. */ | |
39 | #if defined __cplusplus && (__cplusplus >= 199711L || __GNUC_PREREQ (4, 4)) | |
d8387c7b UD |
40 | # define __CORRECT_ISO_CPP_STRING_H_PROTO |
41 | #endif | |
42 | ||
28f540f4 | 43 | |
7a5affeb | 44 | __BEGIN_NAMESPACE_STD |
28f540f4 | 45 | /* Copy N bytes of SRC to DEST. */ |
a784e502 UD |
46 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src, |
47 | size_t __n) __THROW __nonnull ((1, 2)); | |
28f540f4 RM |
48 | /* Copy N bytes of SRC to DEST, guaranteeing |
49 | correct behavior for overlapping strings. */ | |
a784e502 | 50 | extern void *memmove (void *__dest, const void *__src, size_t __n) |
be27d08c | 51 | __THROW __nonnull ((1, 2)); |
7a5affeb | 52 | __END_NAMESPACE_STD |
28f540f4 RM |
53 | |
54 | /* Copy no more than N bytes of SRC to DEST, stopping when C is found. | |
55 | Return the position in DEST one byte past where C was copied, | |
56 | or NULL if C was not found in the first N bytes of SRC. */ | |
498afc54 | 57 | #if defined __USE_MISC || defined __USE_MISC || defined __USE_XOPEN |
a784e502 | 58 | extern void *memccpy (void *__restrict __dest, const void *__restrict __src, |
98cbe360 | 59 | int __c, size_t __n) |
be27d08c | 60 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
61 | #endif /* SVID. */ |
62 | ||
63 | ||
7a5affeb | 64 | __BEGIN_NAMESPACE_STD |
28f540f4 | 65 | /* Set N bytes of S to C. */ |
be27d08c | 66 | extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1)); |
28f540f4 RM |
67 | |
68 | /* Compare N bytes of S1 and S2. */ | |
a784e502 | 69 | extern int memcmp (const void *__s1, const void *__s2, size_t __n) |
be27d08c | 70 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 RM |
71 | |
72 | /* Search N bytes of S for C. */ | |
d8387c7b | 73 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
74 | extern "C++" |
75 | { | |
76 | extern void *memchr (void *__s, int __c, size_t __n) | |
d8387c7b | 77 | __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1)); |
a784e502 | 78 | extern const void *memchr (const void *__s, int __c, size_t __n) |
d8387c7b | 79 | __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1)); |
8585cb74 UD |
80 | |
81 | # ifdef __OPTIMIZE__ | |
82 | __extern_always_inline void * | |
83 | memchr (void *__s, int __c, size_t __n) __THROW | |
84 | { | |
85 | return __builtin_memchr (__s, __c, __n); | |
86 | } | |
87 | ||
a784e502 UD |
88 | __extern_always_inline const void * |
89 | memchr (const void *__s, int __c, size_t __n) __THROW | |
8585cb74 UD |
90 | { |
91 | return __builtin_memchr (__s, __c, __n); | |
92 | } | |
93 | # endif | |
94 | } | |
d8387c7b | 95 | #else |
a784e502 | 96 | extern void *memchr (const void *__s, int __c, size_t __n) |
be27d08c | 97 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 98 | #endif |
7a5affeb | 99 | __END_NAMESPACE_STD |
28f540f4 | 100 | |
482eec0d UD |
101 | #ifdef __USE_GNU |
102 | /* Search in S for C. This is similar to `memchr' but there is no | |
103 | length limit. */ | |
d8387c7b UD |
104 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
105 | extern "C++" void *rawmemchr (void *__s, int __c) | |
106 | __THROW __asm ("rawmemchr") __attribute_pure__ __nonnull ((1)); | |
a784e502 | 107 | extern "C++" const void *rawmemchr (const void *__s, int __c) |
d8387c7b UD |
108 | __THROW __asm ("rawmemchr") __attribute_pure__ __nonnull ((1)); |
109 | # else | |
a784e502 | 110 | extern void *rawmemchr (const void *__s, int __c) |
be27d08c | 111 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 112 | # endif |
ca747856 RM |
113 | |
114 | /* Search N bytes of S for the final occurrence of C. */ | |
d8387c7b UD |
115 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
116 | extern "C++" void *memrchr (void *__s, int __c, size_t __n) | |
117 | __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1)); | |
a784e502 | 118 | extern "C++" const void *memrchr (const void *__s, int __c, size_t __n) |
d8387c7b UD |
119 | __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1)); |
120 | # else | |
a784e502 | 121 | extern void *memrchr (const void *__s, int __c, size_t __n) |
be27d08c | 122 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 123 | # endif |
482eec0d UD |
124 | #endif |
125 | ||
28f540f4 | 126 | |
7a5affeb | 127 | __BEGIN_NAMESPACE_STD |
28f540f4 | 128 | /* Copy SRC to DEST. */ |
a784e502 | 129 | extern char *strcpy (char *__restrict __dest, const char *__restrict __src) |
be27d08c | 130 | __THROW __nonnull ((1, 2)); |
28f540f4 | 131 | /* Copy no more than N characters of SRC to DEST. */ |
c1422e5b | 132 | extern char *strncpy (char *__restrict __dest, |
a784e502 | 133 | const char *__restrict __src, size_t __n) |
be27d08c | 134 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
135 | |
136 | /* Append SRC onto DEST. */ | |
a784e502 | 137 | extern char *strcat (char *__restrict __dest, const char *__restrict __src) |
be27d08c | 138 | __THROW __nonnull ((1, 2)); |
28f540f4 | 139 | /* Append no more than N characters from SRC onto DEST. */ |
a784e502 | 140 | extern char *strncat (char *__restrict __dest, const char *__restrict __src, |
be27d08c | 141 | size_t __n) __THROW __nonnull ((1, 2)); |
28f540f4 RM |
142 | |
143 | /* Compare S1 and S2. */ | |
a784e502 | 144 | extern int strcmp (const char *__s1, const char *__s2) |
be27d08c | 145 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 | 146 | /* Compare N characters of S1 and S2. */ |
a784e502 | 147 | extern int strncmp (const char *__s1, const char *__s2, size_t __n) |
be27d08c | 148 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 RM |
149 | |
150 | /* Compare the collated forms of S1 and S2. */ | |
a784e502 | 151 | extern int strcoll (const char *__s1, const char *__s2) |
be27d08c | 152 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 | 153 | /* Put a transformation of SRC into no more than N bytes of DEST. */ |
c1422e5b | 154 | extern size_t strxfrm (char *__restrict __dest, |
a784e502 | 155 | const char *__restrict __src, size_t __n) |
be27d08c | 156 | __THROW __nonnull ((2)); |
7a5affeb | 157 | __END_NAMESPACE_STD |
28f540f4 | 158 | |
6cbe890a | 159 | #ifdef __USE_XOPEN2K8 |
c84142e8 UD |
160 | /* The following functions are equivalent to the both above but they |
161 | take the locale they use for the collation as an extra argument. | |
162 | This is not standardsized but something like will come. */ | |
163 | # include <xlocale.h> | |
164 | ||
165 | /* Compare the collated forms of S1 and S2 using rules from L. */ | |
a784e502 | 166 | extern int strcoll_l (const char *__s1, const char *__s2, __locale_t __l) |
be27d08c | 167 | __THROW __attribute_pure__ __nonnull ((1, 2, 3)); |
c84142e8 | 168 | /* Put a transformation of SRC into no more than N bytes of DEST. */ |
a784e502 | 169 | extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n, |
be27d08c | 170 | __locale_t __l) __THROW __nonnull ((2, 4)); |
c84142e8 UD |
171 | #endif |
172 | ||
498afc54 | 173 | #if defined __USE_MISC || defined __USE_MISC || defined __USE_XOPEN_EXTENDED \ |
f095bb72 | 174 | || defined __USE_XOPEN2K8 |
28f540f4 | 175 | /* Duplicate S, returning an identical malloc'd string. */ |
a784e502 | 176 | extern char *strdup (const char *__s) |
be27d08c | 177 | __THROW __attribute_malloc__ __nonnull ((1)); |
28f540f4 RM |
178 | #endif |
179 | ||
6dbe2837 RM |
180 | /* Return a malloc'd copy of at most N bytes of STRING. The |
181 | resultant string is terminated even if no null terminator | |
182 | appears before STRING[N]. */ | |
6cbe890a | 183 | #if defined __USE_XOPEN2K8 |
a784e502 | 184 | extern char *strndup (const char *__string, size_t __n) |
be27d08c | 185 | __THROW __attribute_malloc__ __nonnull ((1)); |
6d52618b | 186 | #endif |
6dbe2837 | 187 | |
377a515b | 188 | #if defined __USE_GNU && defined __GNUC__ |
036cc82f | 189 | /* Duplicate S, returning an identical alloca'd string. */ |
3996f34b | 190 | # define strdupa(s) \ |
036cc82f RM |
191 | (__extension__ \ |
192 | ({ \ | |
a784e502 | 193 | const char *__old = (s); \ |
036cc82f | 194 | size_t __len = strlen (__old) + 1; \ |
8c8f3704 | 195 | char *__new = (char *) __builtin_alloca (__len); \ |
3996f34b | 196 | (char *) memcpy (__new, __old, __len); \ |
036cc82f RM |
197 | })) |
198 | ||
6dbe2837 | 199 | /* Return an alloca'd copy of at most N bytes of string. */ |
3996f34b | 200 | # define strndupa(s, n) \ |
036cc82f RM |
201 | (__extension__ \ |
202 | ({ \ | |
a784e502 | 203 | const char *__old = (s); \ |
036cc82f | 204 | size_t __len = strnlen (__old, (n)); \ |
8c8f3704 | 205 | char *__new = (char *) __builtin_alloca (__len + 1); \ |
036cc82f | 206 | __new[__len] = '\0'; \ |
3996f34b | 207 | (char *) memcpy (__new, __old, __len); \ |
036cc82f | 208 | })) |
02ac66c5 RM |
209 | #endif |
210 | ||
7a5affeb | 211 | __BEGIN_NAMESPACE_STD |
28f540f4 | 212 | /* Find the first occurrence of C in S. */ |
d8387c7b | 213 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
214 | extern "C++" |
215 | { | |
216 | extern char *strchr (char *__s, int __c) | |
d8387c7b | 217 | __THROW __asm ("strchr") __attribute_pure__ __nonnull ((1)); |
a784e502 | 218 | extern const char *strchr (const char *__s, int __c) |
d8387c7b | 219 | __THROW __asm ("strchr") __attribute_pure__ __nonnull ((1)); |
8585cb74 UD |
220 | |
221 | # ifdef __OPTIMIZE__ | |
222 | __extern_always_inline char * | |
223 | strchr (char *__s, int __c) __THROW | |
224 | { | |
225 | return __builtin_strchr (__s, __c); | |
226 | } | |
227 | ||
a784e502 UD |
228 | __extern_always_inline const char * |
229 | strchr (const char *__s, int __c) __THROW | |
8585cb74 UD |
230 | { |
231 | return __builtin_strchr (__s, __c); | |
232 | } | |
233 | # endif | |
234 | } | |
d8387c7b | 235 | #else |
a784e502 | 236 | extern char *strchr (const char *__s, int __c) |
be27d08c | 237 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 238 | #endif |
28f540f4 | 239 | /* Find the last occurrence of C in S. */ |
d8387c7b | 240 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
241 | extern "C++" |
242 | { | |
243 | extern char *strrchr (char *__s, int __c) | |
d8387c7b | 244 | __THROW __asm ("strrchr") __attribute_pure__ __nonnull ((1)); |
a784e502 | 245 | extern const char *strrchr (const char *__s, int __c) |
d8387c7b | 246 | __THROW __asm ("strrchr") __attribute_pure__ __nonnull ((1)); |
8585cb74 UD |
247 | |
248 | # ifdef __OPTIMIZE__ | |
249 | __extern_always_inline char * | |
250 | strrchr (char *__s, int __c) __THROW | |
251 | { | |
252 | return __builtin_strrchr (__s, __c); | |
253 | } | |
254 | ||
a784e502 UD |
255 | __extern_always_inline const char * |
256 | strrchr (const char *__s, int __c) __THROW | |
8585cb74 UD |
257 | { |
258 | return __builtin_strrchr (__s, __c); | |
259 | } | |
260 | # endif | |
261 | } | |
d8387c7b | 262 | #else |
a784e502 | 263 | extern char *strrchr (const char *__s, int __c) |
be27d08c | 264 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 265 | #endif |
7a5affeb | 266 | __END_NAMESPACE_STD |
28f540f4 | 267 | |
c4563d2d | 268 | #ifdef __USE_GNU |
557a9213 | 269 | /* This function is similar to `strchr'. But it returns a pointer to |
c4563d2d | 270 | the closing NUL byte in case C is not found in S. */ |
d8387c7b UD |
271 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
272 | extern "C++" char *strchrnul (char *__s, int __c) | |
273 | __THROW __asm ("strchrnul") __attribute_pure__ __nonnull ((1)); | |
a784e502 | 274 | extern "C++" const char *strchrnul (const char *__s, int __c) |
d8387c7b UD |
275 | __THROW __asm ("strchrnul") __attribute_pure__ __nonnull ((1)); |
276 | # else | |
a784e502 | 277 | extern char *strchrnul (const char *__s, int __c) |
be27d08c | 278 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 279 | # endif |
c4563d2d UD |
280 | #endif |
281 | ||
7a5affeb | 282 | __BEGIN_NAMESPACE_STD |
28f540f4 RM |
283 | /* Return the length of the initial segment of S which |
284 | consists entirely of characters not in REJECT. */ | |
a784e502 | 285 | extern size_t strcspn (const char *__s, const char *__reject) |
be27d08c | 286 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 RM |
287 | /* Return the length of the initial segment of S which |
288 | consists entirely of characters in ACCEPT. */ | |
a784e502 | 289 | extern size_t strspn (const char *__s, const char *__accept) |
be27d08c | 290 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
6d52618b | 291 | /* Find the first occurrence in S of any character in ACCEPT. */ |
d8387c7b | 292 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
293 | extern "C++" |
294 | { | |
a784e502 | 295 | extern char *strpbrk (char *__s, const char *__accept) |
d8387c7b | 296 | __THROW __asm ("strpbrk") __attribute_pure__ __nonnull ((1, 2)); |
a784e502 | 297 | extern const char *strpbrk (const char *__s, const char *__accept) |
d8387c7b | 298 | __THROW __asm ("strpbrk") __attribute_pure__ __nonnull ((1, 2)); |
8585cb74 UD |
299 | |
300 | # ifdef __OPTIMIZE__ | |
301 | __extern_always_inline char * | |
a784e502 | 302 | strpbrk (char *__s, const char *__accept) __THROW |
8585cb74 UD |
303 | { |
304 | return __builtin_strpbrk (__s, __accept); | |
305 | } | |
306 | ||
a784e502 UD |
307 | __extern_always_inline const char * |
308 | strpbrk (const char *__s, const char *__accept) __THROW | |
8585cb74 UD |
309 | { |
310 | return __builtin_strpbrk (__s, __accept); | |
311 | } | |
312 | # endif | |
313 | } | |
d8387c7b | 314 | #else |
a784e502 | 315 | extern char *strpbrk (const char *__s, const char *__accept) |
be27d08c | 316 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
d8387c7b | 317 | #endif |
6d52618b | 318 | /* Find the first occurrence of NEEDLE in HAYSTACK. */ |
d8387c7b | 319 | #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
320 | extern "C++" |
321 | { | |
a784e502 | 322 | extern char *strstr (char *__haystack, const char *__needle) |
d8387c7b | 323 | __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2)); |
a784e502 | 324 | extern const char *strstr (const char *__haystack, const char *__needle) |
d8387c7b | 325 | __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2)); |
8585cb74 UD |
326 | |
327 | # ifdef __OPTIMIZE__ | |
328 | __extern_always_inline char * | |
a784e502 | 329 | strstr (char *__haystack, const char *__needle) __THROW |
8585cb74 UD |
330 | { |
331 | return __builtin_strstr (__haystack, __needle); | |
332 | } | |
333 | ||
a784e502 UD |
334 | __extern_always_inline const char * |
335 | strstr (const char *__haystack, const char *__needle) __THROW | |
8585cb74 UD |
336 | { |
337 | return __builtin_strstr (__haystack, __needle); | |
338 | } | |
339 | # endif | |
340 | } | |
d8387c7b | 341 | #else |
a784e502 | 342 | extern char *strstr (const char *__haystack, const char *__needle) |
be27d08c | 343 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
d8387c7b | 344 | #endif |
f4017d20 | 345 | |
f4017d20 | 346 | |
28f540f4 | 347 | /* Divide S into tokens separated by characters in DELIM. */ |
a784e502 | 348 | extern char *strtok (char *__restrict __s, const char *__restrict __delim) |
be27d08c | 349 | __THROW __nonnull ((2)); |
7a5affeb | 350 | __END_NAMESPACE_STD |
28f540f4 | 351 | |
59dd8641 RM |
352 | /* Divide S into tokens separated by characters in DELIM. Information |
353 | passed between calls are stored in SAVE_PTR. */ | |
c1422e5b | 354 | extern char *__strtok_r (char *__restrict __s, |
a784e502 | 355 | const char *__restrict __delim, |
be27d08c UD |
356 | char **__restrict __save_ptr) |
357 | __THROW __nonnull ((2, 3)); | |
89a9e37b | 358 | #if defined __USE_POSIX || defined __USE_MISC |
a784e502 | 359 | extern char *strtok_r (char *__restrict __s, const char *__restrict __delim, |
be27d08c UD |
360 | char **__restrict __save_ptr) |
361 | __THROW __nonnull ((2, 3)); | |
9d187dd4 | 362 | #endif |
59dd8641 | 363 | |
7a5affeb UD |
364 | #ifdef __USE_GNU |
365 | /* Similar to `strstr' but this function ignores the case of both strings. */ | |
d8387c7b | 366 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
a784e502 | 367 | extern "C++" char *strcasestr (char *__haystack, const char *__needle) |
d8387c7b | 368 | __THROW __asm ("strcasestr") __attribute_pure__ __nonnull ((1, 2)); |
a784e502 UD |
369 | extern "C++" const char *strcasestr (const char *__haystack, |
370 | const char *__needle) | |
d8387c7b UD |
371 | __THROW __asm ("strcasestr") __attribute_pure__ __nonnull ((1, 2)); |
372 | # else | |
a784e502 | 373 | extern char *strcasestr (const char *__haystack, const char *__needle) |
be27d08c | 374 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
d8387c7b | 375 | # endif |
7a5affeb UD |
376 | #endif |
377 | ||
9d187dd4 | 378 | #ifdef __USE_GNU |
6d52618b | 379 | /* Find the first occurrence of NEEDLE in HAYSTACK. |
28f540f4 RM |
380 | NEEDLE is NEEDLELEN bytes long; |
381 | HAYSTACK is HAYSTACKLEN bytes long. */ | |
a784e502 UD |
382 | extern void *memmem (const void *__haystack, size_t __haystacklen, |
383 | const void *__needle, size_t __needlelen) | |
be27d08c | 384 | __THROW __attribute_pure__ __nonnull ((1, 3)); |
9a0a462c UD |
385 | |
386 | /* Copy N bytes of SRC to DEST, return pointer to bytes after the | |
387 | last written byte. */ | |
c1422e5b | 388 | extern void *__mempcpy (void *__restrict __dest, |
a784e502 | 389 | const void *__restrict __src, size_t __n) |
be27d08c | 390 | __THROW __nonnull ((1, 2)); |
c1422e5b | 391 | extern void *mempcpy (void *__restrict __dest, |
a784e502 | 392 | const void *__restrict __src, size_t __n) |
be27d08c | 393 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
394 | #endif |
395 | ||
8d71c7b0 | 396 | |
7a5affeb | 397 | __BEGIN_NAMESPACE_STD |
28f540f4 | 398 | /* Return the length of S. */ |
a784e502 | 399 | extern size_t strlen (const char *__s) |
be27d08c | 400 | __THROW __attribute_pure__ __nonnull ((1)); |
7a5affeb | 401 | __END_NAMESPACE_STD |
28f540f4 | 402 | |
6cbe890a | 403 | #ifdef __USE_XOPEN2K8 |
8d71c7b0 RM |
404 | /* Find the length of STRING, but scan at most MAXLEN characters. |
405 | If no '\0' terminator is found in that many characters, return MAXLEN. */ | |
a784e502 | 406 | extern size_t strnlen (const char *__string, size_t __maxlen) |
be27d08c | 407 | __THROW __attribute_pure__ __nonnull ((1)); |
8d71c7b0 RM |
408 | #endif |
409 | ||
410 | ||
7a5affeb | 411 | __BEGIN_NAMESPACE_STD |
73299943 UD |
412 | /* Return a string describing the meaning of the `errno' code in ERRNUM. */ |
413 | extern char *strerror (int __errnum) __THROW; | |
7a5affeb | 414 | __END_NAMESPACE_STD |
47cbdebd | 415 | #if defined __USE_XOPEN2K || defined __USE_MISC |
61645263 UD |
416 | /* Reentrant version of `strerror'. |
417 | There are 2 flavors of `strerror_r', GNU which returns the string | |
418 | and may or may not use the supplied temporary buffer and POSIX one | |
419 | which fills the string into the buffer. | |
420 | To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L | |
421 | without -D_GNU_SOURCE is needed, otherwise the GNU version is | |
422 | preferred. */ | |
423 | # if defined __USE_XOPEN2K && !defined __USE_GNU | |
424 | /* Fill BUF with a string describing the meaning of the `errno' code in | |
425 | ERRNUM. */ | |
f377d022 UD |
426 | # ifdef __REDIRECT_NTH |
427 | extern int __REDIRECT_NTH (strerror_r, | |
428 | (int __errnum, char *__buf, size_t __buflen), | |
be27d08c | 429 | __xpg_strerror_r) __nonnull ((2)); |
61645263 UD |
430 | # else |
431 | extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen) | |
be27d08c | 432 | __THROW __nonnull ((2)); |
61645263 UD |
433 | # define strerror_r __xpg_strerror_r |
434 | # endif | |
435 | # else | |
436 | /* If a temporary buffer is required, at most BUFLEN bytes of BUF will be | |
437 | used. */ | |
be27d08c | 438 | extern char *strerror_r (int __errnum, char *__buf, size_t __buflen) |
a3aeac40 | 439 | __THROW __nonnull ((2)) __wur; |
61645263 | 440 | # endif |
60478656 | 441 | #endif |
28f540f4 | 442 | |
6cbe890a | 443 | #ifdef __USE_XOPEN2K8 |
4a44ce79 UD |
444 | /* Translate error number to string according to the locale L. */ |
445 | extern char *strerror_l (int __errnum, __locale_t __l) __THROW; | |
446 | #endif | |
447 | ||
448 | ||
61eb22d3 UD |
449 | /* We define this function always since `bzero' is sometimes needed when |
450 | the namespace rules does not allow this. */ | |
be27d08c | 451 | extern void __bzero (void *__s, size_t __n) __THROW __nonnull ((1)); |
61eb22d3 | 452 | |
498afc54 | 453 | #ifdef __USE_MISC |
28f540f4 | 454 | /* Copy N bytes of SRC to DEST (like memmove, but args reversed). */ |
a784e502 | 455 | extern void bcopy (const void *__src, void *__dest, size_t __n) |
be27d08c | 456 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
457 | |
458 | /* Set N bytes of S to 0. */ | |
be27d08c | 459 | extern void bzero (void *__s, size_t __n) __THROW __nonnull ((1)); |
28f540f4 RM |
460 | |
461 | /* Compare N bytes of S1 and S2 (same as memcmp). */ | |
a784e502 | 462 | extern int bcmp (const void *__s1, const void *__s2, size_t __n) |
be27d08c | 463 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 | 464 | |
2c6fe0bd | 465 | /* Find the first occurrence of C in S (same as strchr). */ |
d8387c7b | 466 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
467 | extern "C++" |
468 | { | |
469 | extern char *index (char *__s, int __c) | |
d8387c7b | 470 | __THROW __asm ("index") __attribute_pure__ __nonnull ((1)); |
a784e502 | 471 | extern const char *index (const char *__s, int __c) |
d8387c7b | 472 | __THROW __asm ("index") __attribute_pure__ __nonnull ((1)); |
8585cb74 UD |
473 | |
474 | # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRINGS_H_PROTO | |
475 | __extern_always_inline char * | |
476 | index (char *__s, int __c) __THROW | |
477 | { | |
478 | return __builtin_index (__s, __c); | |
479 | } | |
480 | ||
a784e502 UD |
481 | __extern_always_inline const char * |
482 | index (const char *__s, int __c) __THROW | |
8585cb74 UD |
483 | { |
484 | return __builtin_index (__s, __c); | |
485 | } | |
486 | # endif | |
487 | } | |
d8387c7b | 488 | # else |
a784e502 | 489 | extern char *index (const char *__s, int __c) |
be27d08c | 490 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 491 | # endif |
2c6fe0bd UD |
492 | |
493 | /* Find the last occurrence of C in S (same as strrchr). */ | |
d8387c7b | 494 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
8585cb74 UD |
495 | extern "C++" |
496 | { | |
497 | extern char *rindex (char *__s, int __c) | |
d8387c7b | 498 | __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1)); |
a784e502 | 499 | extern const char *rindex (const char *__s, int __c) |
d8387c7b | 500 | __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1)); |
8585cb74 UD |
501 | |
502 | # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRINGS_H_PROTO | |
503 | __extern_always_inline char * | |
504 | rindex (char *__s, int __c) __THROW | |
505 | { | |
506 | return __builtin_rindex (__s, __c); | |
507 | } | |
508 | ||
a784e502 UD |
509 | __extern_always_inline const char * |
510 | rindex (const char *__s, int __c) __THROW | |
8585cb74 UD |
511 | { |
512 | return __builtin_rindex (__s, __c); | |
513 | } | |
514 | #endif | |
515 | } | |
d8387c7b | 516 | # else |
a784e502 | 517 | extern char *rindex (const char *__s, int __c) |
be27d08c | 518 | __THROW __attribute_pure__ __nonnull ((1)); |
d8387c7b | 519 | # endif |
2c6fe0bd | 520 | |
28f540f4 RM |
521 | /* Return the position of the first bit set in I, or 0 if none are set. |
522 | The least-significant bit is position 1, the most-significant 32. */ | |
976da847 | 523 | extern int ffs (int __i) __THROW __attribute__ ((__const__)); |
bdd421cc UD |
524 | |
525 | /* The following two functions are non-standard but necessary for non-32 bit | |
526 | platforms. */ | |
527 | # ifdef __USE_GNU | |
976da847 | 528 | extern int ffsl (long int __l) __THROW __attribute__ ((__const__)); |
c1422e5b | 529 | __extension__ extern int ffsll (long long int __ll) |
976da847 | 530 | __THROW __attribute__ ((__const__)); |
bdd421cc | 531 | # endif |
28f540f4 RM |
532 | |
533 | /* Compare S1 and S2, ignoring case. */ | |
a784e502 | 534 | extern int strcasecmp (const char *__s1, const char *__s2) |
be27d08c | 535 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 | 536 | |
6e86a7c2 | 537 | /* Compare no more than N chars of S1 and S2, ignoring case. */ |
a784e502 | 538 | extern int strncasecmp (const char *__s1, const char *__s2, size_t __n) |
be27d08c | 539 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
002e2dc4 | 540 | #endif /* Use BSD. */ |
6e86a7c2 | 541 | |
0501d603 UD |
542 | #ifdef __USE_GNU |
543 | /* Again versions of a few functions which use the given locale instead | |
544 | of the global one. */ | |
a784e502 | 545 | extern int strcasecmp_l (const char *__s1, const char *__s2, |
be27d08c UD |
546 | __locale_t __loc) |
547 | __THROW __attribute_pure__ __nonnull ((1, 2, 3)); | |
0501d603 | 548 | |
a784e502 | 549 | extern int strncasecmp_l (const char *__s1, const char *__s2, |
1ab62b32 | 550 | size_t __n, __locale_t __loc) |
be27d08c | 551 | __THROW __attribute_pure__ __nonnull ((1, 2, 4)); |
0501d603 UD |
552 | #endif |
553 | ||
498afc54 | 554 | #ifdef __USE_MISC |
28f540f4 RM |
555 | /* Return the next DELIM-delimited token from *STRINGP, |
556 | terminating it with a '\0', and update *STRINGP to point past it. */ | |
c1422e5b | 557 | extern char *strsep (char **__restrict __stringp, |
a784e502 | 558 | const char *__restrict __delim) |
be27d08c | 559 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
560 | #endif |
561 | ||
6cbe890a | 562 | #ifdef __USE_XOPEN2K8 |
28f540f4 | 563 | /* Return a string describing the meaning of the signal number in SIG. */ |
c1422e5b | 564 | extern char *strsignal (int __sig) __THROW; |
28f540f4 RM |
565 | |
566 | /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ | |
a784e502 | 567 | extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src) |
be27d08c | 568 | __THROW __nonnull ((1, 2)); |
a784e502 | 569 | extern char *stpcpy (char *__restrict __dest, const char *__restrict __src) |
be27d08c | 570 | __THROW __nonnull ((1, 2)); |
28f540f4 RM |
571 | |
572 | /* Copy no more than N characters of SRC to DEST, returning the address of | |
573 | the last character written into DEST. */ | |
c1422e5b | 574 | extern char *__stpncpy (char *__restrict __dest, |
a784e502 | 575 | const char *__restrict __src, size_t __n) |
be27d08c | 576 | __THROW __nonnull ((1, 2)); |
c1422e5b | 577 | extern char *stpncpy (char *__restrict __dest, |
a784e502 | 578 | const char *__restrict __src, size_t __n) |
be27d08c | 579 | __THROW __nonnull ((1, 2)); |
6cbe890a UD |
580 | #endif |
581 | ||
582 | #ifdef __USE_GNU | |
583 | /* Compare S1 and S2 as strings holding name & indices/version numbers. */ | |
a784e502 | 584 | extern int strverscmp (const char *__s1, const char *__s2) |
6cbe890a | 585 | __THROW __attribute_pure__ __nonnull ((1, 2)); |
28f540f4 | 586 | |
28f540f4 | 587 | /* Sautee STRING briskly. */ |
be27d08c | 588 | extern char *strfry (char *__string) __THROW __nonnull ((1)); |
28f540f4 RM |
589 | |
590 | /* Frobnicate N bytes of S. */ | |
be27d08c | 591 | extern void *memfrob (void *__s, size_t __n) __THROW __nonnull ((1)); |
28f540f4 | 592 | |
92f1da4d | 593 | # ifndef basename |
dd33e89f UD |
594 | /* Return the file name within directory of FILENAME. We don't |
595 | declare the function if the `basename' macro is available (defined | |
596 | in <libgen.h>) which makes the XPG version of this function | |
597 | available. */ | |
d8387c7b UD |
598 | # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO |
599 | extern "C++" char *basename (char *__filename) | |
600 | __THROW __asm ("basename") __nonnull ((1)); | |
a784e502 | 601 | extern "C++" const char *basename (const char *__filename) |
d8387c7b UD |
602 | __THROW __asm ("basename") __nonnull ((1)); |
603 | # else | |
a784e502 | 604 | extern char *basename (const char *__filename) __THROW __nonnull ((1)); |
d8387c7b | 605 | # endif |
92f1da4d | 606 | # endif |
84724245 RM |
607 | #endif |
608 | ||
55c14926 | 609 | |
847a35a0 | 610 | #if defined __GNUC__ && __GNUC__ >= 2 |
07c416ed AJ |
611 | # if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ \ |
612 | && !defined __NO_INLINE__ && !defined __cplusplus | |
9a0a462c UD |
613 | /* When using GNU CC we provide some optimized versions of selected |
614 | functions from this header. There are two kinds of optimizations: | |
615 | ||
61952351 UD |
616 | - machine-dependent optimizations, most probably using inline |
617 | assembler code; these might be quite expensive since the code | |
618 | size can increase significantly. | |
9a0a462c UD |
619 | These optimizations are not used unless the symbol |
620 | __USE_STRING_INLINES | |
61952351 | 621 | is defined before including this header. |
9a0a462c UD |
622 | |
623 | - machine-independent optimizations which do not increase the | |
624 | code size significantly and which optimize mainly situations | |
625 | where one or more arguments are compile-time constants. | |
626 | These optimizations are used always when the compiler is | |
61952351 | 627 | taught to optimize. |
9a0a462c | 628 | |
61eb22d3 UD |
629 | One can inhibit all optimizations by defining __NO_STRING_INLINES. */ |
630 | ||
631 | /* Get the machine-dependent optimizations (if any). */ | |
847a35a0 | 632 | # include <bits/string.h> |
9a0a462c UD |
633 | |
634 | /* These are generic optimizations which do not add too much inline code. */ | |
847a35a0 UD |
635 | # include <bits/string2.h> |
636 | # endif | |
b5cc329c | 637 | |
5ac3ea17 | 638 | # if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function |
b5cc329c UD |
639 | /* Functions with security checks. */ |
640 | # include <bits/string3.h> | |
641 | # endif | |
92f1da4d UD |
642 | #endif |
643 | ||
28f540f4 RM |
644 | __END_DECLS |
645 | ||
646 | #endif /* string.h */ |