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-2008 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@
35 /* This feature is available in gcc versions 2.5 and later. */
36 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
37 # define __attribute__(Spec) /* empty */
39 /* The attribute __pure__ was added in gcc 2.96. */
40 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
41 # define __pure__ /* empty */
46 /* The definition of GL_LINK_WARNING is copied here. */
54 /* Return the first occurrence of NEEDLE in HAYSTACK. */
57 # define memmem rpl_memmem
59 # if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@
60 extern void *memmem (void const *__haystack, size_t __haystack_len,
61 void const *__needle, size_t __needle_len)
62 __attribute__ ((__pure__));
64 #elif defined GNULIB_POSIXCHECK
66 # define memmem(a,al,b,bl) \
67 (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \
68 "use gnulib module memmem-simple for portability, " \
69 "and module memmem for speed" ), \
70 memmem (a, al, b, bl))
73 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
77 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
80 #elif defined GNULIB_POSIXCHECK
82 # define mempcpy(a,b,n) \
83 (GL_LINK_WARNING ("mempcpy is unportable - " \
84 "use gnulib module mempcpy for portability"), \
88 /* Search backwards through a block for a byte (specified as an int). */
90 # if ! @HAVE_DECL_MEMRCHR@
91 extern void *memrchr (void const *, int, size_t)
92 __attribute__ ((__pure__));
94 #elif defined GNULIB_POSIXCHECK
96 # define memrchr(a,b,c) \
97 (GL_LINK_WARNING ("memrchr is unportable - " \
98 "use gnulib module memrchr for portability"), \
102 /* Find the first occurrence of C in S. More efficient than
103 memchr(S,C,N), at the expense of undefined behavior if C does not
104 occur within N bytes. */
105 #if @GNULIB_RAWMEMCHR@
106 # if ! @HAVE_RAWMEMCHR@
107 extern void *rawmemchr (void const *__s, int __c_in)
108 __attribute__ ((__pure__));
110 #elif defined GNULIB_POSIXCHECK
112 # define rawmemchr(a,b) \
113 (GL_LINK_WARNING ("rawmemchr is unportable - " \
114 "use gnulib module rawmemchr for portability"), \
118 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
121 extern char *stpcpy (char *restrict __dst, char const *restrict __src);
123 #elif defined GNULIB_POSIXCHECK
125 # define stpcpy(a,b) \
126 (GL_LINK_WARNING ("stpcpy is unportable - " \
127 "use gnulib module stpcpy for portability"), \
131 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
132 last non-NUL byte written into DST. */
134 # if ! @HAVE_STPNCPY@
135 # define stpncpy gnu_stpncpy
136 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
139 #elif defined GNULIB_POSIXCHECK
141 # define stpncpy(a,b,n) \
142 (GL_LINK_WARNING ("stpncpy is unportable - " \
143 "use gnulib module stpncpy for portability"), \
147 #if defined GNULIB_POSIXCHECK
148 /* strchr() does not work with multibyte strings if the locale encoding is
149 GB18030 and the character to be searched is a digit. */
151 # define strchr(s,c) \
152 (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \
153 "in some multibyte locales - " \
154 "use mbschr if you care about internationalization"), \
158 /* Find the first occurrence of C in S or the final NUL byte. */
159 #if @GNULIB_STRCHRNUL@
160 # if ! @HAVE_STRCHRNUL@
161 extern char *strchrnul (char const *__s, int __c_in)
162 __attribute__ ((__pure__));
164 #elif defined GNULIB_POSIXCHECK
166 # define strchrnul(a,b) \
167 (GL_LINK_WARNING ("strchrnul is unportable - " \
168 "use gnulib module strchrnul for portability"), \
172 /* Duplicate S, returning an identical malloc'd string. */
174 # if @REPLACE_STRDUP@
176 # define strdup rpl_strdup
178 # if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@
179 extern char *strdup (char const *__s);
181 #elif defined GNULIB_POSIXCHECK
184 (GL_LINK_WARNING ("strdup is unportable - " \
185 "use gnulib module strdup for portability"), \
189 /* Return a newly allocated copy of at most N bytes of STRING. */
191 # if ! @HAVE_STRNDUP@
193 # define strndup rpl_strndup
195 # if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@
196 extern char *strndup (char const *__string, size_t __n);
198 #elif defined GNULIB_POSIXCHECK
200 # define strndup(a,n) \
201 (GL_LINK_WARNING ("strndup is unportable - " \
202 "use gnulib module strndup for portability"), \
206 /* Find the length (number of bytes) of STRING, but scan at most
207 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
210 # if ! @HAVE_DECL_STRNLEN@
211 extern size_t strnlen (char const *__string, size_t __maxlen)
212 __attribute__ ((__pure__));
214 #elif defined GNULIB_POSIXCHECK
216 # define strnlen(a,n) \
217 (GL_LINK_WARNING ("strnlen is unportable - " \
218 "use gnulib module strnlen for portability"), \
222 #if defined GNULIB_POSIXCHECK
223 /* strcspn() assumes the second argument is a list of single-byte characters.
224 Even in this simple case, it does not work with multibyte strings if the
225 locale encoding is GB18030 and one of the characters to be searched is a
228 # define strcspn(s,a) \
229 (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \
230 "in multibyte locales - " \
231 "use mbscspn if you care about internationalization"), \
235 /* Find the first occurrence in S of any character in ACCEPT. */
237 # if ! @HAVE_STRPBRK@
238 extern char *strpbrk (char const *__s, char const *__accept)
239 __attribute__ ((__pure__));
241 # if defined GNULIB_POSIXCHECK
242 /* strpbrk() 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 strpbrk(s,a) \
248 (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \
249 "in multibyte locales - " \
250 "use mbspbrk if you care about internationalization"), \
253 #elif defined GNULIB_POSIXCHECK
255 # define strpbrk(s,a) \
256 (GL_LINK_WARNING ("strpbrk is unportable - " \
257 "use gnulib module strpbrk for portability"), \
261 #if defined GNULIB_POSIXCHECK
262 /* strspn() assumes the second argument is a list of single-byte characters.
263 Even in this simple case, it cannot work with multibyte strings. */
265 # define strspn(s,a) \
266 (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \
267 "in multibyte locales - " \
268 "use mbsspn if you care about internationalization"), \
272 #if defined GNULIB_POSIXCHECK
273 /* strrchr() does not work with multibyte strings if the locale encoding is
274 GB18030 and the character to be searched is a digit. */
276 # define strrchr(s,c) \
277 (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \
278 "in some multibyte locales - " \
279 "use mbsrchr if you care about internationalization"), \
283 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
284 If one is found, overwrite it with a NUL, and advance *STRINGP
285 to point to the next char after it. Otherwise, set *STRINGP to NULL.
286 If *STRINGP was already NULL, nothing happens.
287 Return the old value of *STRINGP.
289 This is a variant of strtok() that is multithread-safe and supports
292 Caveat: It modifies the original string.
293 Caveat: These functions cannot be used on constant strings.
294 Caveat: The identity of the delimiting character is lost.
295 Caveat: It doesn't work with multibyte strings unless all of the delimiter
296 characters are ASCII characters < 0x30.
298 See also strtok_r(). */
301 extern char *strsep (char **restrict __stringp, char const *restrict __delim);
303 # if defined GNULIB_POSIXCHECK
305 # define strsep(s,d) \
306 (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \
307 "in multibyte locales - " \
308 "use mbssep if you care about internationalization"), \
311 #elif defined GNULIB_POSIXCHECK
313 # define strsep(s,d) \
314 (GL_LINK_WARNING ("strsep is unportable - " \
315 "use gnulib module strsep for portability"), \
320 # if @REPLACE_STRSTR@
321 # define strstr rpl_strstr
322 char *strstr (const char *haystack, const char *needle)
323 __attribute__ ((__pure__));
325 #elif defined GNULIB_POSIXCHECK
326 /* strstr() does not work with multibyte strings if the locale encoding is
327 different from UTF-8:
328 POSIX says that it operates on "strings", and "string" in POSIX is defined
329 as a sequence of bytes, not of characters. */
331 # define strstr(a,b) \
332 (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \
333 "work correctly on character strings in most " \
334 "multibyte locales - " \
335 "use mbsstr if you care about internationalization, " \
336 "or use strstr if you care about speed"), \
340 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
342 #if @GNULIB_STRCASESTR@
343 # if @REPLACE_STRCASESTR@
344 # define strcasestr rpl_strcasestr
346 # if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@
347 extern char *strcasestr (const char *haystack, const char *needle)
348 __attribute__ ((__pure__));
350 #elif defined GNULIB_POSIXCHECK
351 /* strcasestr() does not work with multibyte strings:
352 It is a glibc extension, and glibc implements it only for unibyte
355 # define strcasestr(a,b) \
356 (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \
357 "in multibyte locales - " \
358 "use mbscasestr if you care about " \
359 "internationalization, or use c-strcasestr if you want " \
360 "a locale independent function"), \
364 /* Parse S into tokens separated by characters in DELIM.
365 If S is NULL, the saved pointer in SAVE_PTR is used as
366 the next starting point. For example:
367 char s[] = "-abc-=-def";
369 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
370 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
371 x = strtok_r(NULL, "=", &sp); // x = NULL
374 This is a variant of strtok() that is multithread-safe.
376 For the POSIX documentation for this function, see:
377 http://www.opengroup.org/susv3xsh/strtok.html
379 Caveat: It modifies the original string.
380 Caveat: These functions cannot be used on constant strings.
381 Caveat: The identity of the delimiting character is lost.
382 Caveat: It doesn't work with multibyte strings unless all of the delimiter
383 characters are ASCII characters < 0x30.
385 See also strsep(). */
386 #if @GNULIB_STRTOK_R@
387 # if ! @HAVE_DECL_STRTOK_R@
388 extern char *strtok_r (char *restrict s, char const *restrict delim,
389 char **restrict save_ptr);
391 # if defined GNULIB_POSIXCHECK
393 # define strtok_r(s,d,p) \
394 (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \
395 "in multibyte locales - " \
396 "use mbstok_r if you care about internationalization"), \
399 #elif defined GNULIB_POSIXCHECK
401 # define strtok_r(s,d,p) \
402 (GL_LINK_WARNING ("strtok_r is unportable - " \
403 "use gnulib module strtok_r for portability"), \
408 /* The following functions are not specified by POSIX. They are gnulib
412 /* Return the number of multibyte characters in the character string STRING.
413 This considers multibyte characters, unlike strlen, which counts bytes. */
414 extern size_t mbslen (const char *string);
418 /* Return the number of multibyte characters in the character string starting
419 at STRING and ending at STRING + LEN. */
420 extern size_t mbsnlen (const char *string, size_t len);
424 /* Locate the first single-byte character C in the character string STRING,
425 and return a pointer to it. Return NULL if C is not found in STRING.
426 Unlike strchr(), this function works correctly in multibyte locales with
427 encodings such as GB18030. */
428 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
429 extern char * mbschr (const char *string, int c);
433 /* Locate the last single-byte character C in the character string STRING,
434 and return a pointer to it. Return NULL if C is not found in STRING.
435 Unlike strrchr(), this function works correctly in multibyte locales with
436 encodings such as GB18030. */
437 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
438 extern char * mbsrchr (const char *string, int c);
442 /* Find the first occurrence of the character string NEEDLE in the character
443 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
444 Unlike strstr(), this function works correctly in multibyte locales with
445 encodings different from UTF-8. */
446 extern char * mbsstr (const char *haystack, const char *needle);
449 #if @GNULIB_MBSCASECMP@
450 /* Compare the character strings S1 and S2, ignoring case, returning less than,
451 equal to or greater than zero if S1 is lexicographically less than, equal to
453 Note: This function may, in multibyte locales, return 0 for strings of
455 Unlike strcasecmp(), this function works correctly in multibyte locales. */
456 extern int mbscasecmp (const char *s1, const char *s2);
459 #if @GNULIB_MBSNCASECMP@
460 /* Compare the initial segment of the character string S1 consisting of at most
461 N characters with the initial segment of the character string S2 consisting
462 of at most N characters, ignoring case, returning less than, equal to or
463 greater than zero if the initial segment of S1 is lexicographically less
464 than, equal to or greater than the initial segment of S2.
465 Note: This function may, in multibyte locales, return 0 for initial segments
466 of different lengths!
467 Unlike strncasecmp(), this function works correctly in multibyte locales.
468 But beware that N is not a byte count but a character count! */
469 extern int mbsncasecmp (const char *s1, const char *s2, size_t n);
472 #if @GNULIB_MBSPCASECMP@
473 /* Compare the initial segment of the character string STRING consisting of
474 at most mbslen (PREFIX) characters with the character string PREFIX,
475 ignoring case, returning less than, equal to or greater than zero if this
476 initial segment is lexicographically less than, equal to or greater than
478 Note: This function may, in multibyte locales, return 0 if STRING is of
479 smaller length than PREFIX!
480 Unlike strncasecmp(), this function works correctly in multibyte
482 extern char * mbspcasecmp (const char *string, const char *prefix);
485 #if @GNULIB_MBSCASESTR@
486 /* Find the first occurrence of the character string NEEDLE in the character
487 string HAYSTACK, using case-insensitive comparison.
488 Note: This function may, in multibyte locales, return success even if
489 strlen (haystack) < strlen (needle) !
490 Unlike strcasestr(), this function works correctly in multibyte locales. */
491 extern char * mbscasestr (const char *haystack, const char *needle);
495 /* Find the first occurrence in the character string STRING of any character
496 in the character string ACCEPT. Return the number of bytes from the
497 beginning of the string to this occurrence, or to the end of the string
499 Unlike strcspn(), this function works correctly in multibyte locales. */
500 extern size_t mbscspn (const char *string, const char *accept);
504 /* Find the first occurrence in the character string STRING of any character
505 in the character string ACCEPT. Return the pointer to it, or NULL if none
507 Unlike strpbrk(), this function works correctly in multibyte locales. */
508 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
509 extern char * mbspbrk (const char *string, const char *accept);
513 /* Find the first occurrence in the character string STRING of any character
514 not in the character string REJECT. Return the number of bytes from the
515 beginning of the string to this occurrence, or to the end of the string
517 Unlike strspn(), this function works correctly in multibyte locales. */
518 extern size_t mbsspn (const char *string, const char *reject);
522 /* Search the next delimiter (multibyte character listed in the character
523 string DELIM) starting at the character string *STRINGP.
524 If one is found, overwrite it with a NUL, and advance *STRINGP to point
525 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
526 If *STRINGP was already NULL, nothing happens.
527 Return the old value of *STRINGP.
529 This is a variant of mbstok_r() that supports empty fields.
531 Caveat: It modifies the original string.
532 Caveat: These functions cannot be used on constant strings.
533 Caveat: The identity of the delimiting character is lost.
535 See also mbstok_r(). */
536 extern char * mbssep (char **stringp, const char *delim);
539 #if @GNULIB_MBSTOK_R@
540 /* Parse the character string STRING into tokens separated by characters in
541 the character string DELIM.
542 If STRING is NULL, the saved pointer in SAVE_PTR is used as
543 the next starting point. For example:
544 char s[] = "-abc-=-def";
546 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
547 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
548 x = mbstok_r(NULL, "=", &sp); // x = NULL
551 Caveat: It modifies the original string.
552 Caveat: These functions cannot be used on constant strings.
553 Caveat: The identity of the delimiting character is lost.
555 See also mbssep(). */
556 extern char * mbstok_r (char *string, const char *delim, char **save_ptr);
559 /* Map any int, typically from errno, into an error message. */
560 #if @GNULIB_STRERROR@
561 # if @REPLACE_STRERROR@
563 # define strerror rpl_strerror
564 extern char *strerror (int);
566 #elif defined GNULIB_POSIXCHECK
568 # define strerror(e) \
569 (GL_LINK_WARNING ("strerror is unportable - " \
570 "use gnulib module strerror to guarantee non-NULL result"), \
574 #if @GNULIB_STRSIGNAL@
575 # if @REPLACE_STRSIGNAL@
576 # define strsignal rpl_strsignal
578 # if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@
579 extern char *strsignal (int __sig);
581 #elif defined GNULIB_POSIXCHECK
583 # define strsignal(a) \
584 (GL_LINK_WARNING ("strsignal is unportable - " \
585 "use gnulib module strsignal for portability"), \
589 #if @GNULIB_STRVERSCMP@
590 # if !@HAVE_STRVERSCMP@
591 extern int strverscmp (const char *, const char *);
593 #elif defined GNULIB_POSIXCHECK
595 # define strverscmp(a, b) \
596 (GL_LINK_WARNING ("strverscmp is unportable - " \
597 "use gnulib module strverscmp for portability"), \
606 #endif /* _GL_STRING_H */
607 #endif /* _GL_STRING_H */