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-2009 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. */
37 /* This feature is available in gcc versions 2.5 and later. */
38 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
39 # define __attribute__(Spec) /* empty */
41 /* The attribute __pure__ was added in gcc 2.96. */
42 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
43 # define __pure__ /* empty */
48 /* The definition of GL_LINK_WARNING is copied here. */
56 /* Return the first instance of C within N bytes of S, or NULL. */
59 # define memchr rpl_memchr
60 extern void *memchr (void const *__s, int __c, size_t __n)
61 __attribute__ ((__pure__));
63 #elif defined GNULIB_POSIXCHECK
65 # define memchr(s,c,n) \
66 (GL_LINK_WARNING ("memchr has platform-specific bugs - " \
67 "use gnulib module memchr for portability" ), \
71 /* Return the first occurrence of NEEDLE in HAYSTACK. */
74 # define memmem rpl_memmem
76 # if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@
77 extern void *memmem (void const *__haystack, size_t __haystack_len,
78 void const *__needle, size_t __needle_len)
79 __attribute__ ((__pure__));
81 #elif defined GNULIB_POSIXCHECK
83 # define memmem(a,al,b,bl) \
84 (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \
85 "use gnulib module memmem-simple for portability, " \
86 "and module memmem for speed" ), \
87 memmem (a, al, b, bl))
90 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
94 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
97 #elif defined GNULIB_POSIXCHECK
99 # define mempcpy(a,b,n) \
100 (GL_LINK_WARNING ("mempcpy is unportable - " \
101 "use gnulib module mempcpy for portability"), \
105 /* Search backwards through a block for a byte (specified as an int). */
107 # if ! @HAVE_DECL_MEMRCHR@
108 extern void *memrchr (void const *, int, size_t)
109 __attribute__ ((__pure__));
111 #elif defined GNULIB_POSIXCHECK
113 # define memrchr(a,b,c) \
114 (GL_LINK_WARNING ("memrchr is unportable - " \
115 "use gnulib module memrchr for portability"), \
119 /* Find the first occurrence of C in S. More efficient than
120 memchr(S,C,N), at the expense of undefined behavior if C does not
121 occur within N bytes. */
122 #if @GNULIB_RAWMEMCHR@
123 # if ! @HAVE_RAWMEMCHR@
124 extern void *rawmemchr (void const *__s, int __c_in)
125 __attribute__ ((__pure__));
127 #elif defined GNULIB_POSIXCHECK
129 # define rawmemchr(a,b) \
130 (GL_LINK_WARNING ("rawmemchr is unportable - " \
131 "use gnulib module rawmemchr for portability"), \
135 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
138 extern char *stpcpy (char *restrict __dst, char const *restrict __src);
140 #elif defined GNULIB_POSIXCHECK
142 # define stpcpy(a,b) \
143 (GL_LINK_WARNING ("stpcpy is unportable - " \
144 "use gnulib module stpcpy for portability"), \
148 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
149 last non-NUL byte written into DST. */
151 # if ! @HAVE_STPNCPY@
152 # define stpncpy gnu_stpncpy
153 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
156 #elif defined GNULIB_POSIXCHECK
158 # define stpncpy(a,b,n) \
159 (GL_LINK_WARNING ("stpncpy is unportable - " \
160 "use gnulib module stpncpy for portability"), \
164 #if defined GNULIB_POSIXCHECK
165 /* strchr() does not work with multibyte strings if the locale encoding is
166 GB18030 and the character to be searched is a digit. */
168 # define strchr(s,c) \
169 (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \
170 "in some multibyte locales - " \
171 "use mbschr if you care about internationalization"), \
175 /* Find the first occurrence of C in S or the final NUL byte. */
176 #if @GNULIB_STRCHRNUL@
177 # if ! @HAVE_STRCHRNUL@
178 extern char *strchrnul (char const *__s, int __c_in)
179 __attribute__ ((__pure__));
181 #elif defined GNULIB_POSIXCHECK
183 # define strchrnul(a,b) \
184 (GL_LINK_WARNING ("strchrnul is unportable - " \
185 "use gnulib module strchrnul for portability"), \
189 /* Duplicate S, returning an identical malloc'd string. */
191 # if @REPLACE_STRDUP@
193 # define strdup rpl_strdup
195 # if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@
196 extern char *strdup (char const *__s);
198 #elif defined GNULIB_POSIXCHECK
201 (GL_LINK_WARNING ("strdup is unportable - " \
202 "use gnulib module strdup for portability"), \
206 /* Return a newly allocated copy of at most N bytes of STRING. */
208 # if @REPLACE_STRNDUP@
210 # define strndup rpl_strndup
212 # if @REPLACE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@
213 extern char *strndup (char const *__string, size_t __n);
215 #elif defined GNULIB_POSIXCHECK
217 # define strndup(a,n) \
218 (GL_LINK_WARNING ("strndup is unportable - " \
219 "use gnulib module strndup for portability"), \
223 /* Find the length (number of bytes) of STRING, but scan at most
224 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
227 # if ! @HAVE_DECL_STRNLEN@
228 extern size_t strnlen (char const *__string, size_t __maxlen)
229 __attribute__ ((__pure__));
231 #elif defined GNULIB_POSIXCHECK
233 # define strnlen(a,n) \
234 (GL_LINK_WARNING ("strnlen is unportable - " \
235 "use gnulib module strnlen for portability"), \
239 #if defined GNULIB_POSIXCHECK
240 /* strcspn() assumes the second argument is a list of single-byte characters.
241 Even in this simple case, it does not work with multibyte strings if the
242 locale encoding is GB18030 and one of the characters to be searched is a
245 # define strcspn(s,a) \
246 (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \
247 "in multibyte locales - " \
248 "use mbscspn if you care about internationalization"), \
252 /* Find the first occurrence in S of any character in ACCEPT. */
254 # if ! @HAVE_STRPBRK@
255 extern char *strpbrk (char const *__s, char const *__accept)
256 __attribute__ ((__pure__));
258 # if defined GNULIB_POSIXCHECK
259 /* strpbrk() assumes the second argument is a list of single-byte characters.
260 Even in this simple case, it does not work with multibyte strings if the
261 locale encoding is GB18030 and one of the characters to be searched is a
264 # define strpbrk(s,a) \
265 (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \
266 "in multibyte locales - " \
267 "use mbspbrk if you care about internationalization"), \
270 #elif defined GNULIB_POSIXCHECK
272 # define strpbrk(s,a) \
273 (GL_LINK_WARNING ("strpbrk is unportable - " \
274 "use gnulib module strpbrk for portability"), \
278 #if defined GNULIB_POSIXCHECK
279 /* strspn() assumes the second argument is a list of single-byte characters.
280 Even in this simple case, it cannot work with multibyte strings. */
282 # define strspn(s,a) \
283 (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \
284 "in multibyte locales - " \
285 "use mbsspn if you care about internationalization"), \
289 #if defined GNULIB_POSIXCHECK
290 /* strrchr() does not work with multibyte strings if the locale encoding is
291 GB18030 and the character to be searched is a digit. */
293 # define strrchr(s,c) \
294 (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \
295 "in some multibyte locales - " \
296 "use mbsrchr if you care about internationalization"), \
300 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
301 If one is found, overwrite it with a NUL, and advance *STRINGP
302 to point to the next char after it. Otherwise, set *STRINGP to NULL.
303 If *STRINGP was already NULL, nothing happens.
304 Return the old value of *STRINGP.
306 This is a variant of strtok() that is multithread-safe and supports
309 Caveat: It modifies the original string.
310 Caveat: These functions cannot be used on constant strings.
311 Caveat: The identity of the delimiting character is lost.
312 Caveat: It doesn't work with multibyte strings unless all of the delimiter
313 characters are ASCII characters < 0x30.
315 See also strtok_r(). */
318 extern char *strsep (char **restrict __stringp, char const *restrict __delim);
320 # if defined GNULIB_POSIXCHECK
322 # define strsep(s,d) \
323 (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \
324 "in multibyte locales - " \
325 "use mbssep if you care about internationalization"), \
328 #elif defined GNULIB_POSIXCHECK
330 # define strsep(s,d) \
331 (GL_LINK_WARNING ("strsep is unportable - " \
332 "use gnulib module strsep for portability"), \
337 # if @REPLACE_STRSTR@
338 # define strstr rpl_strstr
339 char *strstr (const char *haystack, const char *needle)
340 __attribute__ ((__pure__));
342 #elif defined GNULIB_POSIXCHECK
343 /* strstr() does not work with multibyte strings if the locale encoding is
344 different from UTF-8:
345 POSIX says that it operates on "strings", and "string" in POSIX is defined
346 as a sequence of bytes, not of characters. */
348 # define strstr(a,b) \
349 (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \
350 "work correctly on character strings in most " \
351 "multibyte locales - " \
352 "use mbsstr if you care about internationalization, " \
353 "or use strstr if you care about speed"), \
357 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
359 #if @GNULIB_STRCASESTR@
360 # if @REPLACE_STRCASESTR@
361 # define strcasestr rpl_strcasestr
363 # if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@
364 extern char *strcasestr (const char *haystack, const char *needle)
365 __attribute__ ((__pure__));
367 #elif defined GNULIB_POSIXCHECK
368 /* strcasestr() does not work with multibyte strings:
369 It is a glibc extension, and glibc implements it only for unibyte
372 # define strcasestr(a,b) \
373 (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \
374 "in multibyte locales - " \
375 "use mbscasestr if you care about " \
376 "internationalization, or use c-strcasestr if you want " \
377 "a locale independent function"), \
381 /* Parse S into tokens separated by characters in DELIM.
382 If S is NULL, the saved pointer in SAVE_PTR is used as
383 the next starting point. For example:
384 char s[] = "-abc-=-def";
386 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
387 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
388 x = strtok_r(NULL, "=", &sp); // x = NULL
391 This is a variant of strtok() that is multithread-safe.
393 For the POSIX documentation for this function, see:
394 http://www.opengroup.org/susv3xsh/strtok.html
396 Caveat: It modifies the original string.
397 Caveat: These functions cannot be used on constant strings.
398 Caveat: The identity of the delimiting character is lost.
399 Caveat: It doesn't work with multibyte strings unless all of the delimiter
400 characters are ASCII characters < 0x30.
402 See also strsep(). */
403 #if @GNULIB_STRTOK_R@
404 # if @REPLACE_STRTOK_R@
406 # define strtok_r rpl_strtok_r
407 # elif @UNDEFINE_STRTOK_R@
410 # if ! @HAVE_DECL_STRTOK_R@ || @REPLACE_STRTOK_R@
411 extern char *strtok_r (char *restrict s, char const *restrict delim,
412 char **restrict save_ptr);
414 # if defined GNULIB_POSIXCHECK
416 # define strtok_r(s,d,p) \
417 (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \
418 "in multibyte locales - " \
419 "use mbstok_r if you care about internationalization"), \
422 #elif defined GNULIB_POSIXCHECK
424 # define strtok_r(s,d,p) \
425 (GL_LINK_WARNING ("strtok_r is unportable - " \
426 "use gnulib module strtok_r for portability"), \
431 /* The following functions are not specified by POSIX. They are gnulib
435 /* Return the number of multibyte characters in the character string STRING.
436 This considers multibyte characters, unlike strlen, which counts bytes. */
437 extern size_t mbslen (const char *string);
441 /* Return the number of multibyte characters in the character string starting
442 at STRING and ending at STRING + LEN. */
443 extern size_t mbsnlen (const char *string, size_t len);
447 /* Locate the first single-byte character C in the character string STRING,
448 and return a pointer to it. Return NULL if C is not found in STRING.
449 Unlike strchr(), this function works correctly in multibyte locales with
450 encodings such as GB18030. */
451 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
452 extern char * mbschr (const char *string, int c);
456 /* Locate the last single-byte character C in the character string STRING,
457 and return a pointer to it. Return NULL if C is not found in STRING.
458 Unlike strrchr(), this function works correctly in multibyte locales with
459 encodings such as GB18030. */
460 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
461 extern char * mbsrchr (const char *string, int c);
465 /* Find the first occurrence of the character string NEEDLE in the character
466 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
467 Unlike strstr(), this function works correctly in multibyte locales with
468 encodings different from UTF-8. */
469 extern char * mbsstr (const char *haystack, const char *needle);
472 #if @GNULIB_MBSCASECMP@
473 /* Compare the character strings S1 and S2, ignoring case, returning less than,
474 equal to or greater than zero if S1 is lexicographically less than, equal to
476 Note: This function may, in multibyte locales, return 0 for strings of
478 Unlike strcasecmp(), this function works correctly in multibyte locales. */
479 extern int mbscasecmp (const char *s1, const char *s2);
482 #if @GNULIB_MBSNCASECMP@
483 /* Compare the initial segment of the character string S1 consisting of at most
484 N characters with the initial segment of the character string S2 consisting
485 of at most N characters, ignoring case, returning less than, equal to or
486 greater than zero if the initial segment of S1 is lexicographically less
487 than, equal to or greater than the initial segment of S2.
488 Note: This function may, in multibyte locales, return 0 for initial segments
489 of different lengths!
490 Unlike strncasecmp(), this function works correctly in multibyte locales.
491 But beware that N is not a byte count but a character count! */
492 extern int mbsncasecmp (const char *s1, const char *s2, size_t n);
495 #if @GNULIB_MBSPCASECMP@
496 /* Compare the initial segment of the character string STRING consisting of
497 at most mbslen (PREFIX) characters with the character string PREFIX,
498 ignoring case, returning less than, equal to or greater than zero if this
499 initial segment is lexicographically less than, equal to or greater than
501 Note: This function may, in multibyte locales, return 0 if STRING is of
502 smaller length than PREFIX!
503 Unlike strncasecmp(), this function works correctly in multibyte
505 extern char * mbspcasecmp (const char *string, const char *prefix);
508 #if @GNULIB_MBSCASESTR@
509 /* Find the first occurrence of the character string NEEDLE in the character
510 string HAYSTACK, using case-insensitive comparison.
511 Note: This function may, in multibyte locales, return success even if
512 strlen (haystack) < strlen (needle) !
513 Unlike strcasestr(), this function works correctly in multibyte locales. */
514 extern char * mbscasestr (const char *haystack, const char *needle);
518 /* Find the first occurrence in the character string STRING of any character
519 in the character string ACCEPT. Return the number of bytes from the
520 beginning of the string to this occurrence, or to the end of the string
522 Unlike strcspn(), this function works correctly in multibyte locales. */
523 extern size_t mbscspn (const char *string, const char *accept);
527 /* Find the first occurrence in the character string STRING of any character
528 in the character string ACCEPT. Return the pointer to it, or NULL if none
530 Unlike strpbrk(), this function works correctly in multibyte locales. */
531 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
532 extern char * mbspbrk (const char *string, const char *accept);
536 /* Find the first occurrence in the character string STRING of any character
537 not in the character string REJECT. Return the number of bytes from the
538 beginning of the string to this occurrence, or to the end of the string
540 Unlike strspn(), this function works correctly in multibyte locales. */
541 extern size_t mbsspn (const char *string, const char *reject);
545 /* Search the next delimiter (multibyte character listed in the character
546 string DELIM) starting at the character string *STRINGP.
547 If one is found, overwrite it with a NUL, and advance *STRINGP to point
548 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
549 If *STRINGP was already NULL, nothing happens.
550 Return the old value of *STRINGP.
552 This is a variant of mbstok_r() that supports empty fields.
554 Caveat: It modifies the original string.
555 Caveat: These functions cannot be used on constant strings.
556 Caveat: The identity of the delimiting character is lost.
558 See also mbstok_r(). */
559 extern char * mbssep (char **stringp, const char *delim);
562 #if @GNULIB_MBSTOK_R@
563 /* Parse the character string STRING into tokens separated by characters in
564 the character string DELIM.
565 If STRING is NULL, the saved pointer in SAVE_PTR is used as
566 the next starting point. For example:
567 char s[] = "-abc-=-def";
569 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
570 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
571 x = mbstok_r(NULL, "=", &sp); // x = NULL
574 Caveat: It modifies the original string.
575 Caveat: These functions cannot be used on constant strings.
576 Caveat: The identity of the delimiting character is lost.
578 See also mbssep(). */
579 extern char * mbstok_r (char *string, const char *delim, char **save_ptr);
582 /* Map any int, typically from errno, into an error message. */
583 #if @GNULIB_STRERROR@
584 # if @REPLACE_STRERROR@
586 # define strerror rpl_strerror
587 extern char *strerror (int);
589 #elif defined GNULIB_POSIXCHECK
591 # define strerror(e) \
592 (GL_LINK_WARNING ("strerror is unportable - " \
593 "use gnulib module strerror to guarantee non-NULL result"), \
597 #if @GNULIB_STRSIGNAL@
598 # if @REPLACE_STRSIGNAL@
599 # define strsignal rpl_strsignal
601 # if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@
602 extern char *strsignal (int __sig);
604 #elif defined GNULIB_POSIXCHECK
606 # define strsignal(a) \
607 (GL_LINK_WARNING ("strsignal is unportable - " \
608 "use gnulib module strsignal for portability"), \
612 #if @GNULIB_STRVERSCMP@
613 # if !@HAVE_STRVERSCMP@
614 extern int strverscmp (const char *, const char *);
616 #elif defined GNULIB_POSIXCHECK
618 # define strverscmp(a, b) \
619 (GL_LINK_WARNING ("strverscmp is unportable - " \
620 "use gnulib module strverscmp for portability"), \
629 #endif /* _GL_STRING_H */
630 #endif /* _GL_STRING_H */