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. */
23 /* The include_next requires a split double-inclusion guard. */
24 #@INCLUDE_NEXT@ @NEXT_STRING_H@
31 /* This feature is available in gcc versions 2.5 and later. */
32 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
33 # define __attribute__(Spec) /* empty */
35 /* The attribute __pure__ was added in gcc 2.96. */
36 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
37 # define __pure__ /* empty */
42 /* The definition of GL_LINK_WARNING is copied here. */
50 /* Return the first occurrence of NEEDLE in HAYSTACK. */
53 # define memmem rpl_memmem
55 # if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@
56 extern void *memmem (void const *__haystack, size_t __haystack_len,
57 void const *__needle, size_t __needle_len)
58 __attribute__ ((__pure__));
60 #elif defined GNULIB_POSIXCHECK
62 # define memmem(a,al,b,bl) \
63 (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \
64 "use gnulib module memmem-simple for portability, " \
65 "and module memmem for speed" ), \
66 memmem (a, al, b, bl))
69 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
73 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
76 #elif defined GNULIB_POSIXCHECK
78 # define mempcpy(a,b,n) \
79 (GL_LINK_WARNING ("mempcpy is unportable - " \
80 "use gnulib module mempcpy for portability"), \
84 /* Search backwards through a block for a byte (specified as an int). */
86 # if ! @HAVE_DECL_MEMRCHR@
87 extern void *memrchr (void const *, int, size_t)
88 __attribute__ ((__pure__));
90 #elif defined GNULIB_POSIXCHECK
92 # define memrchr(a,b,c) \
93 (GL_LINK_WARNING ("memrchr is unportable - " \
94 "use gnulib module memrchr for portability"), \
98 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
101 extern char *stpcpy (char *restrict __dst, char const *restrict __src);
103 #elif defined GNULIB_POSIXCHECK
105 # define stpcpy(a,b) \
106 (GL_LINK_WARNING ("stpcpy is unportable - " \
107 "use gnulib module stpcpy for portability"), \
111 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
112 last non-NUL byte written into DST. */
114 # if ! @HAVE_STPNCPY@
115 # define stpncpy gnu_stpncpy
116 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
119 #elif defined GNULIB_POSIXCHECK
121 # define stpncpy(a,b,n) \
122 (GL_LINK_WARNING ("stpncpy is unportable - " \
123 "use gnulib module stpncpy for portability"), \
127 #if defined GNULIB_POSIXCHECK
128 /* strchr() does not work with multibyte strings if the locale encoding is
129 GB18030 and the character to be searched is a digit. */
131 # define strchr(s,c) \
132 (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \
133 "in some multibyte locales - " \
134 "use mbschr if you care about internationalization"), \
138 /* Find the first occurrence of C in S or the final NUL byte. */
139 #if @GNULIB_STRCHRNUL@
140 # if ! @HAVE_STRCHRNUL@
141 extern char *strchrnul (char const *__s, int __c_in)
142 __attribute__ ((__pure__));
144 #elif defined GNULIB_POSIXCHECK
146 # define strchrnul(a,b) \
147 (GL_LINK_WARNING ("strchrnul is unportable - " \
148 "use gnulib module strchrnul for portability"), \
152 /* Duplicate S, returning an identical malloc'd string. */
154 # if ! @HAVE_DECL_STRDUP@ && ! defined strdup
155 extern char *strdup (char const *__s);
157 #elif defined GNULIB_POSIXCHECK
160 (GL_LINK_WARNING ("strdup is unportable - " \
161 "use gnulib module strdup for portability"), \
165 /* Return a newly allocated copy of at most N bytes of STRING. */
167 # if ! @HAVE_STRNDUP@
169 # define strndup rpl_strndup
171 # if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@
172 extern char *strndup (char const *__string, size_t __n);
174 #elif defined GNULIB_POSIXCHECK
176 # define strndup(a,n) \
177 (GL_LINK_WARNING ("strndup is unportable - " \
178 "use gnulib module strndup for portability"), \
182 /* Find the length (number of bytes) of STRING, but scan at most
183 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
186 # if ! @HAVE_DECL_STRNLEN@
187 extern size_t strnlen (char const *__string, size_t __maxlen)
188 __attribute__ ((__pure__));
190 #elif defined GNULIB_POSIXCHECK
192 # define strnlen(a,n) \
193 (GL_LINK_WARNING ("strnlen is unportable - " \
194 "use gnulib module strnlen for portability"), \
198 #if defined GNULIB_POSIXCHECK
199 /* strcspn() assumes the second argument is a list of single-byte characters.
200 Even in this simple case, it does not work with multibyte strings if the
201 locale encoding is GB18030 and one of the characters to be searched is a
204 # define strcspn(s,a) \
205 (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \
206 "in multibyte locales - " \
207 "use mbscspn if you care about internationalization"), \
211 /* Find the first occurrence in S of any character in ACCEPT. */
213 # if ! @HAVE_STRPBRK@
214 extern char *strpbrk (char const *__s, char const *__accept)
215 __attribute__ ((__pure__));
217 # if defined GNULIB_POSIXCHECK
218 /* strpbrk() assumes the second argument is a list of single-byte characters.
219 Even in this simple case, it does not work with multibyte strings if the
220 locale encoding is GB18030 and one of the characters to be searched is a
223 # define strpbrk(s,a) \
224 (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \
225 "in multibyte locales - " \
226 "use mbspbrk if you care about internationalization"), \
229 #elif defined GNULIB_POSIXCHECK
231 # define strpbrk(s,a) \
232 (GL_LINK_WARNING ("strpbrk is unportable - " \
233 "use gnulib module strpbrk for portability"), \
237 #if defined GNULIB_POSIXCHECK
238 /* strspn() assumes the second argument is a list of single-byte characters.
239 Even in this simple case, it cannot work with multibyte strings. */
241 # define strspn(s,a) \
242 (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \
243 "in multibyte locales - " \
244 "use mbsspn if you care about internationalization"), \
248 #if defined GNULIB_POSIXCHECK
249 /* strrchr() does not work with multibyte strings if the locale encoding is
250 GB18030 and the character to be searched is a digit. */
252 # define strrchr(s,c) \
253 (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \
254 "in some multibyte locales - " \
255 "use mbsrchr if you care about internationalization"), \
259 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
260 If one is found, overwrite it with a NUL, and advance *STRINGP
261 to point to the next char after it. Otherwise, set *STRINGP to NULL.
262 If *STRINGP was already NULL, nothing happens.
263 Return the old value of *STRINGP.
265 This is a variant of strtok() that is multithread-safe and supports
268 Caveat: It modifies the original string.
269 Caveat: These functions cannot be used on constant strings.
270 Caveat: The identity of the delimiting character is lost.
271 Caveat: It doesn't work with multibyte strings unless all of the delimiter
272 characters are ASCII characters < 0x30.
274 See also strtok_r(). */
277 extern char *strsep (char **restrict __stringp, char const *restrict __delim);
279 # if defined GNULIB_POSIXCHECK
281 # define strsep(s,d) \
282 (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \
283 "in multibyte locales - " \
284 "use mbssep if you care about internationalization"), \
287 #elif defined GNULIB_POSIXCHECK
289 # define strsep(s,d) \
290 (GL_LINK_WARNING ("strsep is unportable - " \
291 "use gnulib module strsep for portability"), \
296 # if @REPLACE_STRSTR@
297 # define strstr rpl_strstr
298 char *strstr (const char *haystack, const char *needle)
299 __attribute__ ((__pure__));
301 #elif defined GNULIB_POSIXCHECK
302 /* strstr() does not work with multibyte strings if the locale encoding is
303 different from UTF-8:
304 POSIX says that it operates on "strings", and "string" in POSIX is defined
305 as a sequence of bytes, not of characters. */
307 # define strstr(a,b) \
308 (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \
309 "work correctly on character strings in most " \
310 "multibyte locales - " \
311 "use mbsstr if you care about internationalization, " \
312 "or use strstr if you care about speed"), \
316 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
318 #if @GNULIB_STRCASESTR@
319 # if @REPLACE_STRCASESTR@
320 # define strcasestr rpl_strcasestr
322 # if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@
323 extern char *strcasestr (const char *haystack, const char *needle)
324 __attribute__ ((__pure__));
326 #elif defined GNULIB_POSIXCHECK
327 /* strcasestr() does not work with multibyte strings:
328 It is a glibc extension, and glibc implements it only for unibyte
331 # define strcasestr(a,b) \
332 (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \
333 "in multibyte locales - " \
334 "use mbscasestr if you care about " \
335 "internationalization, or use c-strcasestr if you want " \
336 "a locale independent function"), \
340 /* Parse S into tokens separated by characters in DELIM.
341 If S is NULL, the saved pointer in SAVE_PTR is used as
342 the next starting point. For example:
343 char s[] = "-abc-=-def";
345 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
346 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
347 x = strtok_r(NULL, "=", &sp); // x = NULL
350 This is a variant of strtok() that is multithread-safe.
352 For the POSIX documentation for this function, see:
353 http://www.opengroup.org/susv3xsh/strtok.html
355 Caveat: It modifies the original string.
356 Caveat: These functions cannot be used on constant strings.
357 Caveat: The identity of the delimiting character is lost.
358 Caveat: It doesn't work with multibyte strings unless all of the delimiter
359 characters are ASCII characters < 0x30.
361 See also strsep(). */
362 #if @GNULIB_STRTOK_R@
363 # if ! @HAVE_DECL_STRTOK_R@
364 extern char *strtok_r (char *restrict s, char const *restrict delim,
365 char **restrict save_ptr);
367 # if defined GNULIB_POSIXCHECK
369 # define strtok_r(s,d,p) \
370 (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \
371 "in multibyte locales - " \
372 "use mbstok_r if you care about internationalization"), \
375 #elif defined GNULIB_POSIXCHECK
377 # define strtok_r(s,d,p) \
378 (GL_LINK_WARNING ("strtok_r is unportable - " \
379 "use gnulib module strtok_r for portability"), \
384 /* The following functions are not specified by POSIX. They are gnulib
388 /* Return the number of multibyte characters in the character string STRING.
389 This considers multibyte characters, unlike strlen, which counts bytes. */
390 extern size_t mbslen (const char *string);
394 /* Return the number of multibyte characters in the character string starting
395 at STRING and ending at STRING + LEN. */
396 extern size_t mbsnlen (const char *string, size_t len);
400 /* Locate the first single-byte character C in the character string STRING,
401 and return a pointer to it. Return NULL if C is not found in STRING.
402 Unlike strchr(), this function works correctly in multibyte locales with
403 encodings such as GB18030. */
404 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
405 extern char * mbschr (const char *string, int c);
409 /* Locate the last single-byte character C in the character string STRING,
410 and return a pointer to it. Return NULL if C is not found in STRING.
411 Unlike strrchr(), this function works correctly in multibyte locales with
412 encodings such as GB18030. */
413 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
414 extern char * mbsrchr (const char *string, int c);
418 /* Find the first occurrence of the character string NEEDLE in the character
419 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
420 Unlike strstr(), this function works correctly in multibyte locales with
421 encodings different from UTF-8. */
422 extern char * mbsstr (const char *haystack, const char *needle);
425 #if @GNULIB_MBSCASECMP@
426 /* Compare the character strings S1 and S2, ignoring case, returning less than,
427 equal to or greater than zero if S1 is lexicographically less than, equal to
429 Note: This function may, in multibyte locales, return 0 for strings of
431 Unlike strcasecmp(), this function works correctly in multibyte locales. */
432 extern int mbscasecmp (const char *s1, const char *s2);
435 #if @GNULIB_MBSNCASECMP@
436 /* Compare the initial segment of the character string S1 consisting of at most
437 N characters with the initial segment of the character string S2 consisting
438 of at most N characters, ignoring case, returning less than, equal to or
439 greater than zero if the initial segment of S1 is lexicographically less
440 than, equal to or greater than the initial segment of S2.
441 Note: This function may, in multibyte locales, return 0 for initial segments
442 of different lengths!
443 Unlike strncasecmp(), this function works correctly in multibyte locales.
444 But beware that N is not a byte count but a character count! */
445 extern int mbsncasecmp (const char *s1, const char *s2, size_t n);
448 #if @GNULIB_MBSPCASECMP@
449 /* Compare the initial segment of the character string STRING consisting of
450 at most mbslen (PREFIX) characters with the character string PREFIX,
451 ignoring case, returning less than, equal to or greater than zero if this
452 initial segment is lexicographically less than, equal to or greater than
454 Note: This function may, in multibyte locales, return 0 if STRING is of
455 smaller length than PREFIX!
456 Unlike strncasecmp(), this function works correctly in multibyte
458 extern char * mbspcasecmp (const char *string, const char *prefix);
461 #if @GNULIB_MBSCASESTR@
462 /* Find the first occurrence of the character string NEEDLE in the character
463 string HAYSTACK, using case-insensitive comparison.
464 Note: This function may, in multibyte locales, return success even if
465 strlen (haystack) < strlen (needle) !
466 Unlike strcasestr(), this function works correctly in multibyte locales. */
467 extern char * mbscasestr (const char *haystack, const char *needle);
471 /* Find the first occurrence in the character string STRING of any character
472 in the character string ACCEPT. Return the number of bytes from the
473 beginning of the string to this occurrence, or to the end of the string
475 Unlike strcspn(), this function works correctly in multibyte locales. */
476 extern size_t mbscspn (const char *string, const char *accept);
480 /* Find the first occurrence in the character string STRING of any character
481 in the character string ACCEPT. Return the pointer to it, or NULL if none
483 Unlike strpbrk(), this function works correctly in multibyte locales. */
484 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
485 extern char * mbspbrk (const char *string, const char *accept);
489 /* Find the first occurrence in the character string STRING of any character
490 not in the character string REJECT. Return the number of bytes from the
491 beginning of the string to this occurrence, or to the end of the string
493 Unlike strspn(), this function works correctly in multibyte locales. */
494 extern size_t mbsspn (const char *string, const char *reject);
498 /* Search the next delimiter (multibyte character listed in the character
499 string DELIM) starting at the character string *STRINGP.
500 If one is found, overwrite it with a NUL, and advance *STRINGP to point
501 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
502 If *STRINGP was already NULL, nothing happens.
503 Return the old value of *STRINGP.
505 This is a variant of mbstok_r() that supports empty fields.
507 Caveat: It modifies the original string.
508 Caveat: These functions cannot be used on constant strings.
509 Caveat: The identity of the delimiting character is lost.
511 See also mbstok_r(). */
512 extern char * mbssep (char **stringp, const char *delim);
515 #if @GNULIB_MBSTOK_R@
516 /* Parse the character string STRING into tokens separated by characters in
517 the character string DELIM.
518 If STRING is NULL, the saved pointer in SAVE_PTR is used as
519 the next starting point. For example:
520 char s[] = "-abc-=-def";
522 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
523 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
524 x = mbstok_r(NULL, "=", &sp); // x = NULL
527 Caveat: It modifies the original string.
528 Caveat: These functions cannot be used on constant strings.
529 Caveat: The identity of the delimiting character is lost.
531 See also mbssep(). */
532 extern char * mbstok_r (char *string, const char *delim, char **save_ptr);
535 /* Map any int, typically from errno, into an error message. */
536 #if @GNULIB_STRERROR@
537 # if @REPLACE_STRERROR@
539 # define strerror rpl_strerror
540 extern char *strerror (int);
542 #elif defined GNULIB_POSIXCHECK
544 # define strerror(e) \
545 (GL_LINK_WARNING ("strerror is unportable - " \
546 "use gnulib module strerror to guarantee non-NULL result"), \
550 #if @GNULIB_STRSIGNAL@
551 # if @REPLACE_STRSIGNAL@
552 # define strsignal rpl_strsignal
554 # if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@
555 extern char *strsignal (int __sig);
557 #elif defined GNULIB_POSIXCHECK
559 # define strsignal(a) \
560 (GL_LINK_WARNING ("strsignal is unportable - " \
561 "use gnulib module strsignal for portability"), \
570 #endif /* _GL_STRING_H */
571 #endif /* _GL_STRING_H */