1 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2 /* A GNU-like <string.h>.
4 Copyright (C) 1995-1996, 2001-2008 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 /* The include_next requires a split double-inclusion guard. */
23 #include_next <string.h>
30 /* This feature is available in gcc versions 2.5 and later. */
31 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
32 # define __attribute__(Spec) /* empty */
34 /* The attribute __pure__ was added in gcc 2.96. */
35 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
36 # define __pure__ /* empty */
41 /* The definition of GL_LINK_WARNING is copied here. */
42 /* GL_LINK_WARNING("literal string") arranges to emit the literal string as
43 a linker warning on most glibc systems.
44 We use a linker warning rather than a preprocessor warning, because
45 #warning cannot be used inside macros. */
46 #ifndef GL_LINK_WARNING
47 /* This works on platforms with GNU ld and ELF object format.
48 Testing __GLIBC__ is sufficient for asserting that GNU ld is in use.
49 Testing __ELF__ guarantees the ELF object format.
50 Testing __GNUC__ is necessary for the compound expression syntax. */
51 # if defined __GLIBC__ && defined __ELF__ && defined __GNUC__
52 # define GL_LINK_WARNING(message) \
53 GL_LINK_WARNING1 (__FILE__, __LINE__, message)
54 # define GL_LINK_WARNING1(file, line, message) \
55 GL_LINK_WARNING2 (file, line, message) /* macroexpand file and line */
56 # define GL_LINK_WARNING2(file, line, message) \
57 GL_LINK_WARNING3 (file ":" #line ": warning: " message)
58 # define GL_LINK_WARNING3(message) \
59 ({ static const char warning[sizeof (message)] \
60 __attribute__ ((__unused__, \
61 __section__ (".gnu.warning"), \
67 # define GL_LINK_WARNING(message) ((void) 0)
77 /* Return the first occurrence of NEEDLE in HAYSTACK. */
80 # define memmem rpl_memmem
83 extern void *memmem (void const *__haystack, size_t __haystack_len,
84 void const *__needle, size_t __needle_len)
85 __attribute__ ((__pure__));
87 #elif defined GNULIB_POSIXCHECK
89 # define memmem(a,al,b,bl) \
90 (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \
91 "use gnulib module memmem-simple for portability, " \
92 "and module memmem for speed" ), \
93 memmem (a, al, b, bl))
96 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
100 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
103 #elif defined GNULIB_POSIXCHECK
105 # define mempcpy(a,b,n) \
106 (GL_LINK_WARNING ("mempcpy is unportable - " \
107 "use gnulib module mempcpy for portability"), \
111 /* Search backwards through a block for a byte (specified as an int). */
114 extern void *memrchr (void const *, int, size_t)
115 __attribute__ ((__pure__));
117 #elif defined GNULIB_POSIXCHECK
119 # define memrchr(a,b,c) \
120 (GL_LINK_WARNING ("memrchr is unportable - " \
121 "use gnulib module memrchr for portability"), \
125 /* Find the first occurrence of C in S. More efficient than
126 memchr(S,C,N), at the expense of undefined behavior if C does not
127 occur within N bytes. */
130 extern void *rawmemchr (void const *__s, int __c_in)
131 __attribute__ ((__pure__));
133 #elif defined GNULIB_POSIXCHECK
135 # define rawmemchr(a,b) \
136 (GL_LINK_WARNING ("rawmemchr is unportable - " \
137 "use gnulib module rawmemchr for portability"), \
141 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
144 extern char *stpcpy (char *restrict __dst, char const *restrict __src);
146 #elif defined GNULIB_POSIXCHECK
148 # define stpcpy(a,b) \
149 (GL_LINK_WARNING ("stpcpy is unportable - " \
150 "use gnulib module stpcpy for portability"), \
154 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
155 last non-NUL byte written into DST. */
158 # define stpncpy gnu_stpncpy
159 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
162 #elif defined GNULIB_POSIXCHECK
164 # define stpncpy(a,b,n) \
165 (GL_LINK_WARNING ("stpncpy is unportable - " \
166 "use gnulib module stpncpy for portability"), \
170 #if defined GNULIB_POSIXCHECK
171 /* strchr() does not work with multibyte strings if the locale encoding is
172 GB18030 and the character to be searched is a digit. */
174 # define strchr(s,c) \
175 (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \
176 "in some multibyte locales - " \
177 "use mbschr if you care about internationalization"), \
181 /* Find the first occurrence of C in S or the final NUL byte. */
184 extern char *strchrnul (char const *__s, int __c_in)
185 __attribute__ ((__pure__));
187 #elif defined GNULIB_POSIXCHECK
189 # define strchrnul(a,b) \
190 (GL_LINK_WARNING ("strchrnul is unportable - " \
191 "use gnulib module strchrnul for portability"), \
195 /* Duplicate S, returning an identical malloc'd string. */
197 # if ! 1 && ! defined strdup
198 extern char *strdup (char const *__s);
200 #elif defined GNULIB_POSIXCHECK
203 (GL_LINK_WARNING ("strdup is unportable - " \
204 "use gnulib module strdup for portability"), \
208 /* Return a newly allocated copy of at most N bytes of STRING. */
212 # define strndup rpl_strndup
215 extern char *strndup (char const *__string, size_t __n);
217 #elif defined GNULIB_POSIXCHECK
219 # define strndup(a,n) \
220 (GL_LINK_WARNING ("strndup is unportable - " \
221 "use gnulib module strndup for portability"), \
225 /* Find the length (number of bytes) of STRING, but scan at most
226 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
230 extern size_t strnlen (char const *__string, size_t __maxlen)
231 __attribute__ ((__pure__));
233 #elif defined GNULIB_POSIXCHECK
235 # define strnlen(a,n) \
236 (GL_LINK_WARNING ("strnlen is unportable - " \
237 "use gnulib module strnlen for portability"), \
241 #if defined GNULIB_POSIXCHECK
242 /* strcspn() assumes the second argument is a list of single-byte characters.
243 Even in this simple case, it does not work with multibyte strings if the
244 locale encoding is GB18030 and one of the characters to be searched is a
247 # define strcspn(s,a) \
248 (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \
249 "in multibyte locales - " \
250 "use mbscspn if you care about internationalization"), \
254 /* Find the first occurrence in S of any character in ACCEPT. */
257 extern char *strpbrk (char const *__s, char const *__accept)
258 __attribute__ ((__pure__));
260 # if defined GNULIB_POSIXCHECK
261 /* strpbrk() assumes the second argument is a list of single-byte characters.
262 Even in this simple case, it does not work with multibyte strings if the
263 locale encoding is GB18030 and one of the characters to be searched is a
266 # define strpbrk(s,a) \
267 (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \
268 "in multibyte locales - " \
269 "use mbspbrk if you care about internationalization"), \
272 #elif defined GNULIB_POSIXCHECK
274 # define strpbrk(s,a) \
275 (GL_LINK_WARNING ("strpbrk is unportable - " \
276 "use gnulib module strpbrk for portability"), \
280 #if defined GNULIB_POSIXCHECK
281 /* strspn() assumes the second argument is a list of single-byte characters.
282 Even in this simple case, it cannot work with multibyte strings. */
284 # define strspn(s,a) \
285 (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \
286 "in multibyte locales - " \
287 "use mbsspn if you care about internationalization"), \
291 #if defined GNULIB_POSIXCHECK
292 /* strrchr() does not work with multibyte strings if the locale encoding is
293 GB18030 and the character to be searched is a digit. */
295 # define strrchr(s,c) \
296 (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \
297 "in some multibyte locales - " \
298 "use mbsrchr if you care about internationalization"), \
302 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
303 If one is found, overwrite it with a NUL, and advance *STRINGP
304 to point to the next char after it. Otherwise, set *STRINGP to NULL.
305 If *STRINGP was already NULL, nothing happens.
306 Return the old value of *STRINGP.
308 This is a variant of strtok() that is multithread-safe and supports
311 Caveat: It modifies the original string.
312 Caveat: These functions cannot be used on constant strings.
313 Caveat: The identity of the delimiting character is lost.
314 Caveat: It doesn't work with multibyte strings unless all of the delimiter
315 characters are ASCII characters < 0x30.
317 See also strtok_r(). */
320 extern char *strsep (char **restrict __stringp, char const *restrict __delim);
322 # if defined GNULIB_POSIXCHECK
324 # define strsep(s,d) \
325 (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \
326 "in multibyte locales - " \
327 "use mbssep if you care about internationalization"), \
330 #elif defined GNULIB_POSIXCHECK
332 # define strsep(s,d) \
333 (GL_LINK_WARNING ("strsep is unportable - " \
334 "use gnulib module strsep for portability"), \
340 # define strstr rpl_strstr
341 char *strstr (const char *haystack, const char *needle)
342 __attribute__ ((__pure__));
344 #elif defined GNULIB_POSIXCHECK
345 /* strstr() does not work with multibyte strings if the locale encoding is
346 different from UTF-8:
347 POSIX says that it operates on "strings", and "string" in POSIX is defined
348 as a sequence of bytes, not of characters. */
350 # define strstr(a,b) \
351 (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \
352 "work correctly on character strings in most " \
353 "multibyte locales - " \
354 "use mbsstr if you care about internationalization, " \
355 "or use strstr if you care about speed"), \
359 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
363 # define strcasestr rpl_strcasestr
366 extern char *strcasestr (const char *haystack, const char *needle)
367 __attribute__ ((__pure__));
369 #elif defined GNULIB_POSIXCHECK
370 /* strcasestr() does not work with multibyte strings:
371 It is a glibc extension, and glibc implements it only for unibyte
374 # define strcasestr(a,b) \
375 (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \
376 "in multibyte locales - " \
377 "use mbscasestr if you care about " \
378 "internationalization, or use c-strcasestr if you want " \
379 "a locale independent function"), \
383 /* Parse S into tokens separated by characters in DELIM.
384 If S is NULL, the saved pointer in SAVE_PTR is used as
385 the next starting point. For example:
386 char s[] = "-abc-=-def";
388 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
389 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
390 x = strtok_r(NULL, "=", &sp); // x = NULL
393 This is a variant of strtok() that is multithread-safe.
395 For the POSIX documentation for this function, see:
396 http://www.opengroup.org/susv3xsh/strtok.html
398 Caveat: It modifies the original string.
399 Caveat: These functions cannot be used on constant strings.
400 Caveat: The identity of the delimiting character is lost.
401 Caveat: It doesn't work with multibyte strings unless all of the delimiter
402 characters are ASCII characters < 0x30.
404 See also strsep(). */
407 extern char *strtok_r (char *restrict s, char const *restrict delim,
408 char **restrict save_ptr);
410 # if defined GNULIB_POSIXCHECK
412 # define strtok_r(s,d,p) \
413 (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \
414 "in multibyte locales - " \
415 "use mbstok_r if you care about internationalization"), \
418 #elif defined GNULIB_POSIXCHECK
420 # define strtok_r(s,d,p) \
421 (GL_LINK_WARNING ("strtok_r is unportable - " \
422 "use gnulib module strtok_r for portability"), \
427 /* The following functions are not specified by POSIX. They are gnulib
431 /* Return the number of multibyte characters in the character string STRING.
432 This considers multibyte characters, unlike strlen, which counts bytes. */
433 extern size_t mbslen (const char *string);
437 /* Return the number of multibyte characters in the character string starting
438 at STRING and ending at STRING + LEN. */
439 extern size_t mbsnlen (const char *string, size_t len);
443 /* Locate the first single-byte character C in the character string STRING,
444 and return a pointer to it. Return NULL if C is not found in STRING.
445 Unlike strchr(), this function works correctly in multibyte locales with
446 encodings such as GB18030. */
447 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
448 extern char * mbschr (const char *string, int c);
452 /* Locate the last single-byte character C in the character string STRING,
453 and return a pointer to it. Return NULL if C is not found in STRING.
454 Unlike strrchr(), this function works correctly in multibyte locales with
455 encodings such as GB18030. */
456 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
457 extern char * mbsrchr (const char *string, int c);
461 /* Find the first occurrence of the character string NEEDLE in the character
462 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
463 Unlike strstr(), this function works correctly in multibyte locales with
464 encodings different from UTF-8. */
465 extern char * mbsstr (const char *haystack, const char *needle);
469 /* Compare the character strings S1 and S2, ignoring case, returning less than,
470 equal to or greater than zero if S1 is lexicographically less than, equal to
472 Note: This function may, in multibyte locales, return 0 for strings of
474 Unlike strcasecmp(), this function works correctly in multibyte locales. */
475 extern int mbscasecmp (const char *s1, const char *s2);
479 /* Compare the initial segment of the character string S1 consisting of at most
480 N characters with the initial segment of the character string S2 consisting
481 of at most N characters, ignoring case, returning less than, equal to or
482 greater than zero if the initial segment of S1 is lexicographically less
483 than, equal to or greater than the initial segment of S2.
484 Note: This function may, in multibyte locales, return 0 for initial segments
485 of different lengths!
486 Unlike strncasecmp(), this function works correctly in multibyte locales.
487 But beware that N is not a byte count but a character count! */
488 extern int mbsncasecmp (const char *s1, const char *s2, size_t n);
492 /* Compare the initial segment of the character string STRING consisting of
493 at most mbslen (PREFIX) characters with the character string PREFIX,
494 ignoring case, returning less than, equal to or greater than zero if this
495 initial segment is lexicographically less than, equal to or greater than
497 Note: This function may, in multibyte locales, return 0 if STRING is of
498 smaller length than PREFIX!
499 Unlike strncasecmp(), this function works correctly in multibyte
501 extern char * mbspcasecmp (const char *string, const char *prefix);
505 /* Find the first occurrence of the character string NEEDLE in the character
506 string HAYSTACK, using case-insensitive comparison.
507 Note: This function may, in multibyte locales, return success even if
508 strlen (haystack) < strlen (needle) !
509 Unlike strcasestr(), this function works correctly in multibyte locales. */
510 extern char * mbscasestr (const char *haystack, const char *needle);
514 /* Find the first occurrence in the character string STRING of any character
515 in the character string ACCEPT. Return the number of bytes from the
516 beginning of the string to this occurrence, or to the end of the string
518 Unlike strcspn(), this function works correctly in multibyte locales. */
519 extern size_t mbscspn (const char *string, const char *accept);
523 /* Find the first occurrence in the character string STRING of any character
524 in the character string ACCEPT. Return the pointer to it, or NULL if none
526 Unlike strpbrk(), this function works correctly in multibyte locales. */
527 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
528 extern char * mbspbrk (const char *string, const char *accept);
532 /* Find the first occurrence in the character string STRING of any character
533 not in the character string REJECT. Return the number of bytes from the
534 beginning of the string to this occurrence, or to the end of the string
536 Unlike strspn(), this function works correctly in multibyte locales. */
537 extern size_t mbsspn (const char *string, const char *reject);
541 /* Search the next delimiter (multibyte character listed in the character
542 string DELIM) starting at the character string *STRINGP.
543 If one is found, overwrite it with a NUL, and advance *STRINGP to point
544 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
545 If *STRINGP was already NULL, nothing happens.
546 Return the old value of *STRINGP.
548 This is a variant of mbstok_r() that supports empty fields.
550 Caveat: It modifies the original string.
551 Caveat: These functions cannot be used on constant strings.
552 Caveat: The identity of the delimiting character is lost.
554 See also mbstok_r(). */
555 extern char * mbssep (char **stringp, const char *delim);
559 /* Parse the character string STRING into tokens separated by characters in
560 the character string DELIM.
561 If STRING is NULL, the saved pointer in SAVE_PTR is used as
562 the next starting point. For example:
563 char s[] = "-abc-=-def";
565 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
566 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
567 x = mbstok_r(NULL, "=", &sp); // x = NULL
570 Caveat: It modifies the original string.
571 Caveat: These functions cannot be used on constant strings.
572 Caveat: The identity of the delimiting character is lost.
574 See also mbssep(). */
575 extern char * mbstok_r (char *string, const char *delim, char **save_ptr);
578 /* Map any int, typically from errno, into an error message. */
582 # define strerror rpl_strerror
583 extern char *strerror (int);
585 #elif defined GNULIB_POSIXCHECK
587 # define strerror(e) \
588 (GL_LINK_WARNING ("strerror is unportable - " \
589 "use gnulib module strerror to guarantee non-NULL result"), \
595 # define strsignal rpl_strsignal
598 extern char *strsignal (int __sig);
600 #elif defined GNULIB_POSIXCHECK
602 # define strsignal(a) \
603 (GL_LINK_WARNING ("strsignal is unportable - " \
604 "use gnulib module strsignal for portability"), \
613 #endif /* _GL_STRING_H */
614 #endif /* _GL_STRING_H */