1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* A GNU-like <string.h>.
5 Copyright (C) 1995-1996, 2001-2010 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
24 @PRAGMA_SYSTEM_HEADER@
27 /* The include_next requires a split double-inclusion guard. */
28 #@INCLUDE_NEXT@ @NEXT_STRING_H@
33 /* NetBSD 5.0 mis-defines NULL. */
36 /* MirBSD defines mbslen as a macro. */
37 #if @GNULIB_MBSLEN@ && defined __MirBSD__
42 /* This feature is available in gcc versions 2.5 and later. */
43 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
44 # define __attribute__(Spec) /* empty */
46 /* The attribute __pure__ was added in gcc 2.96. */
47 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
48 # define __pure__ /* empty */
53 /* The definition of GL_LINK_WARNING is copied here. */
55 /* The definition of _GL_ARG_NONNULL is copied here. */
63 /* Return the first instance of C within N bytes of S, or NULL. */
66 # define memchr rpl_memchr
67 extern void *memchr (void const *__s, int __c, size_t __n)
68 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
70 #elif defined GNULIB_POSIXCHECK
72 # define memchr(s,c,n) \
73 (GL_LINK_WARNING ("memchr has platform-specific bugs - " \
74 "use gnulib module memchr for portability" ), \
78 /* Return the first occurrence of NEEDLE in HAYSTACK. */
81 # define memmem rpl_memmem
83 # if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@
84 extern void *memmem (void const *__haystack, size_t __haystack_len,
85 void const *__needle, size_t __needle_len)
86 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3));
88 #elif defined GNULIB_POSIXCHECK
90 # define memmem(a,al,b,bl) \
91 (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \
92 "use gnulib module memmem-simple for portability, " \
93 "and module memmem for speed" ), \
94 memmem (a, al, b, bl))
97 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
100 # if ! @HAVE_MEMPCPY@
101 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
103 _GL_ARG_NONNULL ((1, 2));
105 #elif defined GNULIB_POSIXCHECK
107 # define mempcpy(a,b,n) \
108 (GL_LINK_WARNING ("mempcpy is unportable - " \
109 "use gnulib module mempcpy for portability"), \
113 /* Search backwards through a block for a byte (specified as an int). */
115 # if ! @HAVE_DECL_MEMRCHR@
116 extern void *memrchr (void const *, int, size_t)
117 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
119 #elif defined GNULIB_POSIXCHECK
121 # define memrchr(a,b,c) \
122 (GL_LINK_WARNING ("memrchr is unportable - " \
123 "use gnulib module memrchr for portability"), \
127 /* Find the first occurrence of C in S. More efficient than
128 memchr(S,C,N), at the expense of undefined behavior if C does not
129 occur within N bytes. */
130 #if @GNULIB_RAWMEMCHR@
131 # if ! @HAVE_RAWMEMCHR@
132 extern void *rawmemchr (void const *__s, int __c_in)
133 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
135 #elif defined GNULIB_POSIXCHECK
137 # define rawmemchr(a,b) \
138 (GL_LINK_WARNING ("rawmemchr is unportable - " \
139 "use gnulib module rawmemchr for portability"), \
143 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
146 extern char *stpcpy (char *restrict __dst, char const *restrict __src)
147 _GL_ARG_NONNULL ((1, 2));
149 #elif defined GNULIB_POSIXCHECK
151 # define stpcpy(a,b) \
152 (GL_LINK_WARNING ("stpcpy is unportable - " \
153 "use gnulib module stpcpy for portability"), \
157 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
158 last non-NUL byte written into DST. */
160 # if ! @HAVE_STPNCPY@
161 # define stpncpy gnu_stpncpy
162 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
164 _GL_ARG_NONNULL ((1, 2));
166 #elif defined GNULIB_POSIXCHECK
168 # define stpncpy(a,b,n) \
169 (GL_LINK_WARNING ("stpncpy is unportable - " \
170 "use gnulib module stpncpy for portability"), \
174 #if defined GNULIB_POSIXCHECK
175 /* strchr() does not work with multibyte strings if the locale encoding is
176 GB18030 and the character to be searched is a digit. */
178 # define strchr(s,c) \
179 (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \
180 "in some multibyte locales - " \
181 "use mbschr if you care about internationalization"), \
185 /* Find the first occurrence of C in S or the final NUL byte. */
186 #if @GNULIB_STRCHRNUL@
187 # if ! @HAVE_STRCHRNUL@
188 extern char *strchrnul (char const *__s, int __c_in)
189 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
191 #elif defined GNULIB_POSIXCHECK
193 # define strchrnul(a,b) \
194 (GL_LINK_WARNING ("strchrnul is unportable - " \
195 "use gnulib module strchrnul for portability"), \
199 /* Duplicate S, returning an identical malloc'd string. */
201 # if @REPLACE_STRDUP@
203 # define strdup rpl_strdup
205 # if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@
206 extern char *strdup (char const *__s) _GL_ARG_NONNULL ((1));
208 #elif defined GNULIB_POSIXCHECK
211 (GL_LINK_WARNING ("strdup is unportable - " \
212 "use gnulib module strdup for portability"), \
216 /* Return a newly allocated copy of at most N bytes of STRING. */
218 # if @REPLACE_STRNDUP@
220 # define strndup rpl_strndup
222 # if @REPLACE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@
223 extern char *strndup (char const *__string, size_t __n) _GL_ARG_NONNULL ((1));
225 #elif defined GNULIB_POSIXCHECK
227 # define strndup(a,n) \
228 (GL_LINK_WARNING ("strndup is unportable - " \
229 "use gnulib module strndup for portability"), \
233 /* Find the length (number of bytes) of STRING, but scan at most
234 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
237 # if ! @HAVE_DECL_STRNLEN@
238 extern size_t strnlen (char const *__string, size_t __maxlen)
239 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1));
241 #elif defined GNULIB_POSIXCHECK
243 # define strnlen(a,n) \
244 (GL_LINK_WARNING ("strnlen is unportable - " \
245 "use gnulib module strnlen for portability"), \
249 #if defined GNULIB_POSIXCHECK
250 /* strcspn() assumes the second argument is a list of single-byte characters.
251 Even in this simple case, it does not work with multibyte strings if the
252 locale encoding is GB18030 and one of the characters to be searched is a
255 # define strcspn(s,a) \
256 (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \
257 "in multibyte locales - " \
258 "use mbscspn if you care about internationalization"), \
262 /* Find the first occurrence in S of any character in ACCEPT. */
264 # if ! @HAVE_STRPBRK@
265 extern char *strpbrk (char const *__s, char const *__accept)
266 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2));
268 # if defined GNULIB_POSIXCHECK
269 /* strpbrk() assumes the second argument is a list of single-byte characters.
270 Even in this simple case, it does not work with multibyte strings if the
271 locale encoding is GB18030 and one of the characters to be searched is a
274 # define strpbrk(s,a) \
275 (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \
276 "in multibyte locales - " \
277 "use mbspbrk if you care about internationalization"), \
280 #elif defined GNULIB_POSIXCHECK
282 # define strpbrk(s,a) \
283 (GL_LINK_WARNING ("strpbrk is unportable - " \
284 "use gnulib module strpbrk for portability"), \
288 #if defined GNULIB_POSIXCHECK
289 /* strspn() assumes the second argument is a list of single-byte characters.
290 Even in this simple case, it cannot work with multibyte strings. */
292 # define strspn(s,a) \
293 (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \
294 "in multibyte locales - " \
295 "use mbsspn if you care about internationalization"), \
299 #if defined GNULIB_POSIXCHECK
300 /* strrchr() does not work with multibyte strings if the locale encoding is
301 GB18030 and the character to be searched is a digit. */
303 # define strrchr(s,c) \
304 (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \
305 "in some multibyte locales - " \
306 "use mbsrchr if you care about internationalization"), \
310 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
311 If one is found, overwrite it with a NUL, and advance *STRINGP
312 to point to the next char after it. Otherwise, set *STRINGP to NULL.
313 If *STRINGP was already NULL, nothing happens.
314 Return the old value of *STRINGP.
316 This is a variant of strtok() that is multithread-safe and supports
319 Caveat: It modifies the original string.
320 Caveat: These functions cannot be used on constant strings.
321 Caveat: The identity of the delimiting character is lost.
322 Caveat: It doesn't work with multibyte strings unless all of the delimiter
323 characters are ASCII characters < 0x30.
325 See also strtok_r(). */
328 extern char *strsep (char **restrict __stringp, char const *restrict __delim)
329 _GL_ARG_NONNULL ((1, 2));
331 # if defined GNULIB_POSIXCHECK
333 # define strsep(s,d) \
334 (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \
335 "in multibyte locales - " \
336 "use mbssep if you care about internationalization"), \
339 #elif defined GNULIB_POSIXCHECK
341 # define strsep(s,d) \
342 (GL_LINK_WARNING ("strsep is unportable - " \
343 "use gnulib module strsep for portability"), \
348 # if @REPLACE_STRSTR@
349 # define strstr rpl_strstr
350 extern char *strstr (const char *haystack, const char *needle)
351 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2));
353 #elif defined GNULIB_POSIXCHECK
354 /* strstr() does not work with multibyte strings if the locale encoding is
355 different from UTF-8:
356 POSIX says that it operates on "strings", and "string" in POSIX is defined
357 as a sequence of bytes, not of characters. */
359 # define strstr(a,b) \
360 (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \
361 "work correctly on character strings in most " \
362 "multibyte locales - " \
363 "use mbsstr if you care about internationalization, " \
364 "or use strstr if you care about speed"), \
368 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
370 #if @GNULIB_STRCASESTR@
371 # if @REPLACE_STRCASESTR@
372 # define strcasestr rpl_strcasestr
374 # if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@
375 extern char *strcasestr (const char *haystack, const char *needle)
376 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2));
378 #elif defined GNULIB_POSIXCHECK
379 /* strcasestr() does not work with multibyte strings:
380 It is a glibc extension, and glibc implements it only for unibyte
383 # define strcasestr(a,b) \
384 (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \
385 "in multibyte locales - " \
386 "use mbscasestr if you care about " \
387 "internationalization, or use c-strcasestr if you want " \
388 "a locale independent function"), \
392 /* Parse S into tokens separated by characters in DELIM.
393 If S is NULL, the saved pointer in SAVE_PTR is used as
394 the next starting point. For example:
395 char s[] = "-abc-=-def";
397 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
398 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
399 x = strtok_r(NULL, "=", &sp); // x = NULL
402 This is a variant of strtok() that is multithread-safe.
404 For the POSIX documentation for this function, see:
405 http://www.opengroup.org/susv3xsh/strtok.html
407 Caveat: It modifies the original string.
408 Caveat: These functions cannot be used on constant strings.
409 Caveat: The identity of the delimiting character is lost.
410 Caveat: It doesn't work with multibyte strings unless all of the delimiter
411 characters are ASCII characters < 0x30.
413 See also strsep(). */
414 #if @GNULIB_STRTOK_R@
415 # if @REPLACE_STRTOK_R@
417 # define strtok_r rpl_strtok_r
418 # elif @UNDEFINE_STRTOK_R@
421 # if ! @HAVE_DECL_STRTOK_R@ || @REPLACE_STRTOK_R@
422 extern char *strtok_r (char *restrict s, char const *restrict delim,
423 char **restrict save_ptr)
424 _GL_ARG_NONNULL ((2, 3));
426 # if defined GNULIB_POSIXCHECK
428 # define strtok_r(s,d,p) \
429 (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \
430 "in multibyte locales - " \
431 "use mbstok_r if you care about internationalization"), \
434 #elif defined GNULIB_POSIXCHECK
436 # define strtok_r(s,d,p) \
437 (GL_LINK_WARNING ("strtok_r is unportable - " \
438 "use gnulib module strtok_r for portability"), \
443 /* The following functions are not specified by POSIX. They are gnulib
447 /* Return the number of multibyte characters in the character string STRING.
448 This considers multibyte characters, unlike strlen, which counts bytes. */
449 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
452 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
453 # define mbslen rpl_mbslen
455 extern size_t mbslen (const char *string) _GL_ARG_NONNULL ((1));
459 /* Return the number of multibyte characters in the character string starting
460 at STRING and ending at STRING + LEN. */
461 extern size_t mbsnlen (const char *string, size_t len) _GL_ARG_NONNULL ((1));
465 /* Locate the first single-byte character C in the character string STRING,
466 and return a pointer to it. Return NULL if C is not found in STRING.
467 Unlike strchr(), this function works correctly in multibyte locales with
468 encodings such as GB18030. */
469 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
470 extern char * mbschr (const char *string, int c) _GL_ARG_NONNULL ((1));
474 /* Locate the last single-byte character C in the character string STRING,
475 and return a pointer to it. Return NULL if C is not found in STRING.
476 Unlike strrchr(), this function works correctly in multibyte locales with
477 encodings such as GB18030. */
478 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
479 extern char * mbsrchr (const char *string, int c) _GL_ARG_NONNULL ((1));
483 /* Find the first occurrence of the character string NEEDLE in the character
484 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
485 Unlike strstr(), this function works correctly in multibyte locales with
486 encodings different from UTF-8. */
487 extern char * mbsstr (const char *haystack, const char *needle)
488 _GL_ARG_NONNULL ((1, 2));
491 #if @GNULIB_MBSCASECMP@
492 /* Compare the character strings S1 and S2, ignoring case, returning less than,
493 equal to or greater than zero if S1 is lexicographically less than, equal to
495 Note: This function may, in multibyte locales, return 0 for strings of
497 Unlike strcasecmp(), this function works correctly in multibyte locales. */
498 extern int mbscasecmp (const char *s1, const char *s2)
499 _GL_ARG_NONNULL ((1, 2));
502 #if @GNULIB_MBSNCASECMP@
503 /* Compare the initial segment of the character string S1 consisting of at most
504 N characters with the initial segment of the character string S2 consisting
505 of at most N characters, ignoring case, returning less than, equal to or
506 greater than zero if the initial segment of S1 is lexicographically less
507 than, equal to or greater than the initial segment of S2.
508 Note: This function may, in multibyte locales, return 0 for initial segments
509 of different lengths!
510 Unlike strncasecmp(), this function works correctly in multibyte locales.
511 But beware that N is not a byte count but a character count! */
512 extern int mbsncasecmp (const char *s1, const char *s2, size_t n)
513 _GL_ARG_NONNULL ((1, 2));
516 #if @GNULIB_MBSPCASECMP@
517 /* Compare the initial segment of the character string STRING consisting of
518 at most mbslen (PREFIX) characters with the character string PREFIX,
519 ignoring case, returning less than, equal to or greater than zero if this
520 initial segment is lexicographically less than, equal to or greater than
522 Note: This function may, in multibyte locales, return 0 if STRING is of
523 smaller length than PREFIX!
524 Unlike strncasecmp(), this function works correctly in multibyte
526 extern char * mbspcasecmp (const char *string, const char *prefix)
527 _GL_ARG_NONNULL ((1, 2));
530 #if @GNULIB_MBSCASESTR@
531 /* Find the first occurrence of the character string NEEDLE in the character
532 string HAYSTACK, using case-insensitive comparison.
533 Note: This function may, in multibyte locales, return success even if
534 strlen (haystack) < strlen (needle) !
535 Unlike strcasestr(), this function works correctly in multibyte locales. */
536 extern char * mbscasestr (const char *haystack, const char *needle)
537 _GL_ARG_NONNULL ((1, 2));
541 /* Find the first occurrence in the character string STRING of any character
542 in the character string ACCEPT. Return the number of bytes from the
543 beginning of the string to this occurrence, or to the end of the string
545 Unlike strcspn(), this function works correctly in multibyte locales. */
546 extern size_t mbscspn (const char *string, const char *accept)
547 _GL_ARG_NONNULL ((1, 2));
551 /* Find the first occurrence in the character string STRING of any character
552 in the character string ACCEPT. Return the pointer to it, or NULL if none
554 Unlike strpbrk(), this function works correctly in multibyte locales. */
555 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
556 extern char * mbspbrk (const char *string, const char *accept)
557 _GL_ARG_NONNULL ((1, 2));
561 /* Find the first occurrence in the character string STRING of any character
562 not in the character string REJECT. Return the number of bytes from the
563 beginning of the string to this occurrence, or to the end of the string
565 Unlike strspn(), this function works correctly in multibyte locales. */
566 extern size_t mbsspn (const char *string, const char *reject)
567 _GL_ARG_NONNULL ((1, 2));
571 /* Search the next delimiter (multibyte character listed in the character
572 string DELIM) starting at the character string *STRINGP.
573 If one is found, overwrite it with a NUL, and advance *STRINGP to point
574 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
575 If *STRINGP was already NULL, nothing happens.
576 Return the old value of *STRINGP.
578 This is a variant of mbstok_r() that supports empty fields.
580 Caveat: It modifies the original string.
581 Caveat: These functions cannot be used on constant strings.
582 Caveat: The identity of the delimiting character is lost.
584 See also mbstok_r(). */
585 extern char * mbssep (char **stringp, const char *delim)
586 _GL_ARG_NONNULL ((1, 2));
589 #if @GNULIB_MBSTOK_R@
590 /* Parse the character string STRING into tokens separated by characters in
591 the character string DELIM.
592 If STRING is NULL, the saved pointer in SAVE_PTR is used as
593 the next starting point. For example:
594 char s[] = "-abc-=-def";
596 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
597 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
598 x = mbstok_r(NULL, "=", &sp); // x = NULL
601 Caveat: It modifies the original string.
602 Caveat: These functions cannot be used on constant strings.
603 Caveat: The identity of the delimiting character is lost.
605 See also mbssep(). */
606 extern char * mbstok_r (char *string, const char *delim, char **save_ptr)
607 _GL_ARG_NONNULL ((2, 3));
610 /* Map any int, typically from errno, into an error message. */
611 #if @GNULIB_STRERROR@
612 # if @REPLACE_STRERROR@
614 # define strerror rpl_strerror
615 extern char *strerror (int);
617 #elif defined GNULIB_POSIXCHECK
619 # define strerror(e) \
620 (GL_LINK_WARNING ("strerror is unportable - " \
621 "use gnulib module strerror to guarantee non-NULL result"), \
625 #if @GNULIB_STRSIGNAL@
626 # if @REPLACE_STRSIGNAL@
627 # define strsignal rpl_strsignal
629 # if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@
630 extern char *strsignal (int __sig);
632 #elif defined GNULIB_POSIXCHECK
634 # define strsignal(a) \
635 (GL_LINK_WARNING ("strsignal is unportable - " \
636 "use gnulib module strsignal for portability"), \
640 #if @GNULIB_STRVERSCMP@
641 # if !@HAVE_STRVERSCMP@
642 extern int strverscmp (const char *, const char *) _GL_ARG_NONNULL ((1, 2));
644 #elif defined GNULIB_POSIXCHECK
646 # define strverscmp(a, b) \
647 (GL_LINK_WARNING ("strverscmp is unportable - " \
648 "use gnulib module strverscmp for portability"), \
657 #endif /* _GL_STRING_H */
658 #endif /* _GL_STRING_H */