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 definitions of _GL_FUNCDECL_RPL etc. are copied here. */
55 /* The definition of _GL_ARG_NONNULL is copied here. */
57 /* The definition of _GL_WARN_ON_USE is copied here. */
60 /* Return the first instance of C within N bytes of S, or NULL. */
63 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
64 # define memchr rpl_memchr
66 _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
67 __attribute__ ((__pure__))
68 _GL_ARG_NONNULL ((1)));
69 _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
71 # if defined __SUNPRO_CC
72 /* This compiler defines an overloaded function
73 extern "C" { const void * std::memchr (const void *, int, size_t); }
74 extern "C++" { inline void * std::memchr (void *, int, size_t); }
75 and diagnoses an error
76 "Error: Could not find a match for std::memchr(const void*, int, unsigned)"
78 _GL_CXXALIAS_SYS_CAST2 (memchr,
79 void *, (void const *__s, int __c, size_t __n),
80 void const *, (void const *__s, int __c, size_t __n));
82 _GL_CXXALIAS_SYS (memchr, void *, (void const *__s, int __c, size_t __n));
85 _GL_CXXALIASWARN (memchr);
86 #elif defined GNULIB_POSIXCHECK
88 /* Assume memchr is always declared. */
89 _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
90 "use gnulib module memchr for portability" );
93 /* Return the first occurrence of NEEDLE in HAYSTACK. */
96 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
97 # define memmem rpl_memmem
99 _GL_FUNCDECL_RPL (memmem, void *,
100 (void const *__haystack, size_t __haystack_len,
101 void const *__needle, size_t __needle_len)
102 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
103 _GL_CXXALIAS_RPL (memmem, void *,
104 (void const *__haystack, size_t __haystack_len,
105 void const *__needle, size_t __needle_len));
107 # if ! @HAVE_DECL_MEMMEM@
108 _GL_FUNCDECL_SYS (memmem, void *,
109 (void const *__haystack, size_t __haystack_len,
110 void const *__needle, size_t __needle_len)
111 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
113 _GL_CXXALIAS_SYS (memmem, void *,
114 (void const *__haystack, size_t __haystack_len,
115 void const *__needle, size_t __needle_len));
117 _GL_CXXALIASWARN (memmem);
118 #elif defined GNULIB_POSIXCHECK
120 # if HAVE_RAW_DECL_MEMMEM
121 _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
122 "use gnulib module memmem-simple for portability, "
123 "and module memmem for speed" );
127 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
128 last written byte. */
130 # if ! @HAVE_MEMPCPY@
131 _GL_FUNCDECL_SYS (mempcpy, void *,
132 (void *restrict __dest, void const *restrict __src,
134 _GL_ARG_NONNULL ((1, 2)));
136 _GL_CXXALIAS_SYS (mempcpy, void *,
137 (void *restrict __dest, void const *restrict __src,
139 _GL_CXXALIASWARN (mempcpy);
140 #elif defined GNULIB_POSIXCHECK
142 # if HAVE_RAW_DECL_MEMPCPY
143 _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
144 "use gnulib module mempcpy for portability");
148 /* Search backwards through a block for a byte (specified as an int). */
150 # if ! @HAVE_DECL_MEMRCHR@
151 _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
152 __attribute__ ((__pure__))
153 _GL_ARG_NONNULL ((1)));
155 _GL_CXXALIAS_SYS (memrchr, void *, (void const *, int, size_t));
156 _GL_CXXALIASWARN (memrchr);
157 #elif defined GNULIB_POSIXCHECK
159 # if HAVE_RAW_DECL_MEMRCHR
160 _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
161 "use gnulib module memrchr for portability");
165 /* Find the first occurrence of C in S. More efficient than
166 memchr(S,C,N), at the expense of undefined behavior if C does not
167 occur within N bytes. */
168 #if @GNULIB_RAWMEMCHR@
169 # if ! @HAVE_RAWMEMCHR@
170 _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
171 __attribute__ ((__pure__))
172 _GL_ARG_NONNULL ((1)));
174 _GL_CXXALIAS_SYS (rawmemchr, void *, (void const *__s, int __c_in));
175 _GL_CXXALIASWARN (rawmemchr);
176 #elif defined GNULIB_POSIXCHECK
178 # if HAVE_RAW_DECL_RAWMEMCHR
179 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
180 "use gnulib module rawmemchr for portability");
184 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
187 _GL_FUNCDECL_SYS (stpcpy, char *,
188 (char *restrict __dst, char const *restrict __src)
189 _GL_ARG_NONNULL ((1, 2)));
191 _GL_CXXALIAS_SYS (stpcpy, char *,
192 (char *restrict __dst, char const *restrict __src));
193 _GL_CXXALIASWARN (stpcpy);
194 #elif defined GNULIB_POSIXCHECK
196 # if HAVE_RAW_DECL_STPCPY
197 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
198 "use gnulib module stpcpy for portability");
202 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
203 last non-NUL byte written into DST. */
205 # if ! @HAVE_STPNCPY@
206 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
207 # define stpncpy rpl_stpncpy
209 _GL_FUNCDECL_RPL (stpncpy, char *,
210 (char *restrict __dst, char const *restrict __src,
212 _GL_ARG_NONNULL ((1, 2)));
213 _GL_CXXALIAS_RPL (stpncpy, char *,
214 (char *restrict __dst, char const *restrict __src,
217 _GL_CXXALIAS_SYS (stpncpy, char *,
218 (char *restrict __dst, char const *restrict __src,
221 _GL_CXXALIASWARN (stpncpy);
222 #elif defined GNULIB_POSIXCHECK
224 # if HAVE_RAW_DECL_STPNCPY
225 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
226 "use gnulib module stpncpy for portability");
230 #if defined GNULIB_POSIXCHECK
231 /* strchr() does not work with multibyte strings if the locale encoding is
232 GB18030 and the character to be searched is a digit. */
234 /* Assume strchr is always declared. */
235 _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
236 "in some multibyte locales - "
237 "use mbschr if you care about internationalization");
240 /* Find the first occurrence of C in S or the final NUL byte. */
241 #if @GNULIB_STRCHRNUL@
242 # if ! @HAVE_STRCHRNUL@
243 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
244 __attribute__ ((__pure__))
245 _GL_ARG_NONNULL ((1)));
247 _GL_CXXALIAS_SYS (strchrnul, char *, (char const *__s, int __c_in));
248 _GL_CXXALIASWARN (strchrnul);
249 #elif defined GNULIB_POSIXCHECK
251 # if HAVE_RAW_DECL_STRCHRNUL
252 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
253 "use gnulib module strchrnul for portability");
257 /* Duplicate S, returning an identical malloc'd string. */
259 # if @REPLACE_STRDUP@
260 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
262 # define strdup rpl_strdup
264 _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
265 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
267 # if !(@HAVE_DECL_STRDUP@ || defined strdup)
268 _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
270 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
272 _GL_CXXALIASWARN (strdup);
273 #elif defined GNULIB_POSIXCHECK
275 # if HAVE_RAW_DECL_STRDUP
276 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
277 "use gnulib module strdup for portability");
281 /* Return a newly allocated copy of at most N bytes of STRING. */
283 # if @REPLACE_STRNDUP@
284 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
286 # define strndup rpl_strndup
288 _GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n)
289 _GL_ARG_NONNULL ((1)));
290 _GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n));
292 # if ! @HAVE_DECL_STRNDUP@
293 _GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n)
294 _GL_ARG_NONNULL ((1)));
296 _GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n));
298 _GL_CXXALIASWARN (strndup);
299 #elif defined GNULIB_POSIXCHECK
301 # if HAVE_RAW_DECL_STRNDUP
302 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
303 "use gnulib module strndup for portability");
307 /* Find the length (number of bytes) of STRING, but scan at most
308 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
311 # if ! @HAVE_DECL_STRNLEN@
312 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
313 __attribute__ ((__pure__))
314 _GL_ARG_NONNULL ((1)));
316 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
317 _GL_CXXALIASWARN (strnlen);
318 #elif defined GNULIB_POSIXCHECK
320 # if HAVE_RAW_DECL_STRNLEN
321 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
322 "use gnulib module strnlen for portability");
326 #if defined GNULIB_POSIXCHECK
327 /* strcspn() assumes the second argument is a list of single-byte characters.
328 Even in this simple case, it does not work with multibyte strings if the
329 locale encoding is GB18030 and one of the characters to be searched is a
332 /* Assume strcspn is always declared. */
333 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
334 "in multibyte locales - "
335 "use mbscspn if you care about internationalization");
338 /* Find the first occurrence in S of any character in ACCEPT. */
340 # if ! @HAVE_STRPBRK@
341 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
342 __attribute__ ((__pure__))
343 _GL_ARG_NONNULL ((1, 2)));
345 # if defined __SUNPRO_CC
346 /* This compiler defines an overloaded function
347 extern "C" { const char * strpbrk (const char *, const char *); }
348 extern "C++" { inline char * strpbrk (char *, const char *); }
349 and diagnoses an error
350 "Error: Could not find a match for std::strpbrk(const char*, const char*)"
352 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
353 char *, (char const *__s, char const *__accept),
354 const char *, (char const *__s, char const *__accept));
356 _GL_CXXALIAS_SYS (strpbrk, char *, (char const *__s, char const *__accept));
358 _GL_CXXALIASWARN (strpbrk);
359 # if defined GNULIB_POSIXCHECK
360 /* strpbrk() assumes the second argument is a list of single-byte characters.
361 Even in this simple case, it does not work with multibyte strings if the
362 locale encoding is GB18030 and one of the characters to be searched is a
365 _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
366 "in multibyte locales - "
367 "use mbspbrk if you care about internationalization");
369 #elif defined GNULIB_POSIXCHECK
371 # if HAVE_RAW_DECL_STRPBRK
372 _GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
373 "use gnulib module strpbrk for portability");
377 #if defined GNULIB_POSIXCHECK
378 /* strspn() assumes the second argument is a list of single-byte characters.
379 Even in this simple case, it cannot work with multibyte strings. */
381 /* Assume strspn is always declared. */
382 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
383 "in multibyte locales - "
384 "use mbsspn if you care about internationalization");
387 #if defined GNULIB_POSIXCHECK
388 /* strrchr() does not work with multibyte strings if the locale encoding is
389 GB18030 and the character to be searched is a digit. */
391 /* Assume strrchr is always declared. */
392 _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
393 "in some multibyte locales - "
394 "use mbsrchr if you care about internationalization");
397 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
398 If one is found, overwrite it with a NUL, and advance *STRINGP
399 to point to the next char after it. Otherwise, set *STRINGP to NULL.
400 If *STRINGP was already NULL, nothing happens.
401 Return the old value of *STRINGP.
403 This is a variant of strtok() that is multithread-safe and supports
406 Caveat: It modifies the original string.
407 Caveat: These functions cannot be used on constant strings.
408 Caveat: The identity of the delimiting character is lost.
409 Caveat: It doesn't work with multibyte strings unless all of the delimiter
410 characters are ASCII characters < 0x30.
412 See also strtok_r(). */
415 _GL_FUNCDECL_SYS (strsep, char *,
416 (char **restrict __stringp, char const *restrict __delim)
417 _GL_ARG_NONNULL ((1, 2)));
419 _GL_CXXALIAS_SYS (strsep, char *,
420 (char **restrict __stringp, char const *restrict __delim));
421 _GL_CXXALIASWARN (strsep);
422 # if defined GNULIB_POSIXCHECK
424 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
425 "in multibyte locales - "
426 "use mbssep if you care about internationalization");
428 #elif defined GNULIB_POSIXCHECK
430 # if HAVE_RAW_DECL_STRSEP
431 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
432 "use gnulib module strsep for portability");
437 # if @REPLACE_STRSTR@
438 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
439 # define strstr rpl_strstr
441 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
442 __attribute__ ((__pure__))
443 _GL_ARG_NONNULL ((1, 2)));
444 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
446 _GL_CXXALIAS_SYS (strstr, char *, (const char *haystack, const char *needle));
448 _GL_CXXALIASWARN (strstr);
449 #elif defined GNULIB_POSIXCHECK
450 /* strstr() does not work with multibyte strings if the locale encoding is
451 different from UTF-8:
452 POSIX says that it operates on "strings", and "string" in POSIX is defined
453 as a sequence of bytes, not of characters. */
455 /* Assume strstr is always declared. */
456 _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
457 "work correctly on character strings in most "
458 "multibyte locales - "
459 "use mbsstr if you care about internationalization, "
460 "or use strstr if you care about speed");
463 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
465 #if @GNULIB_STRCASESTR@
466 # if @REPLACE_STRCASESTR@
467 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
468 # define strcasestr rpl_strcasestr
470 _GL_FUNCDECL_RPL (strcasestr, char *,
471 (const char *haystack, const char *needle)
472 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
473 _GL_CXXALIAS_RPL (strcasestr, char *,
474 (const char *haystack, const char *needle));
476 # if ! @HAVE_STRCASESTR@
477 _GL_FUNCDECL_SYS (strcasestr, char *,
478 (const char *haystack, const char *needle)
479 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
481 _GL_CXXALIAS_SYS (strcasestr, char *,
482 (const char *haystack, const char *needle));
484 _GL_CXXALIASWARN (strcasestr);
485 #elif defined GNULIB_POSIXCHECK
486 /* strcasestr() does not work with multibyte strings:
487 It is a glibc extension, and glibc implements it only for unibyte
490 # if HAVE_RAW_DECL_STRCASESTR
491 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
492 "strings in multibyte locales - "
493 "use mbscasestr if you care about "
494 "internationalization, or use c-strcasestr if you want "
495 "a locale independent function");
499 /* Parse S into tokens separated by characters in DELIM.
500 If S is NULL, the saved pointer in SAVE_PTR is used as
501 the next starting point. For example:
502 char s[] = "-abc-=-def";
504 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
505 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
506 x = strtok_r(NULL, "=", &sp); // x = NULL
509 This is a variant of strtok() that is multithread-safe.
511 For the POSIX documentation for this function, see:
512 http://www.opengroup.org/susv3xsh/strtok.html
514 Caveat: It modifies the original string.
515 Caveat: These functions cannot be used on constant strings.
516 Caveat: The identity of the delimiting character is lost.
517 Caveat: It doesn't work with multibyte strings unless all of the delimiter
518 characters are ASCII characters < 0x30.
520 See also strsep(). */
521 #if @GNULIB_STRTOK_R@
522 # if @REPLACE_STRTOK_R@
523 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
525 # define strtok_r rpl_strtok_r
527 _GL_FUNCDECL_RPL (strtok_r, char *,
528 (char *restrict s, char const *restrict delim,
529 char **restrict save_ptr)
530 _GL_ARG_NONNULL ((2, 3)));
531 _GL_CXXALIAS_RPL (strtok_r, char *,
532 (char *restrict s, char const *restrict delim,
533 char **restrict save_ptr));
535 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
538 # if ! @HAVE_DECL_STRTOK_R@
539 _GL_FUNCDECL_SYS (strtok_r, char *,
540 (char *restrict s, char const *restrict delim,
541 char **restrict save_ptr)
542 _GL_ARG_NONNULL ((2, 3)));
544 _GL_CXXALIAS_SYS (strtok_r, char *,
545 (char *restrict s, char const *restrict delim,
546 char **restrict save_ptr));
548 _GL_CXXALIASWARN (strtok_r);
549 # if defined GNULIB_POSIXCHECK
550 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
551 "strings in multibyte locales - "
552 "use mbstok_r if you care about internationalization");
554 #elif defined GNULIB_POSIXCHECK
556 # if HAVE_RAW_DECL_STRTOK_R
557 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
558 "use gnulib module strtok_r for portability");
563 /* The following functions are not specified by POSIX. They are gnulib
567 /* Return the number of multibyte characters in the character string STRING.
568 This considers multibyte characters, unlike strlen, which counts bytes. */
569 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
572 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
573 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
574 # define mbslen rpl_mbslen
576 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
577 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
579 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
580 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
582 _GL_CXXALIASWARN (mbslen);
586 /* Return the number of multibyte characters in the character string starting
587 at STRING and ending at STRING + LEN. */
588 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
589 _GL_ARG_NONNULL ((1));
593 /* Locate the first single-byte character C in the character string STRING,
594 and return a pointer to it. Return NULL if C is not found in STRING.
595 Unlike strchr(), this function works correctly in multibyte locales with
596 encodings such as GB18030. */
598 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
599 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
601 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
602 _GL_ARG_NONNULL ((1)));
603 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
605 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
606 _GL_ARG_NONNULL ((1)));
607 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
609 _GL_CXXALIASWARN (mbschr);
613 /* Locate the last single-byte character C in the character string STRING,
614 and return a pointer to it. Return NULL if C is not found in STRING.
615 Unlike strrchr(), this function works correctly in multibyte locales with
616 encodings such as GB18030. */
618 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
619 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
621 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
622 _GL_ARG_NONNULL ((1)));
623 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
625 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
626 _GL_ARG_NONNULL ((1)));
627 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
629 _GL_CXXALIASWARN (mbsrchr);
633 /* Find the first occurrence of the character string NEEDLE in the character
634 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
635 Unlike strstr(), this function works correctly in multibyte locales with
636 encodings different from UTF-8. */
637 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
638 _GL_ARG_NONNULL ((1, 2));
641 #if @GNULIB_MBSCASECMP@
642 /* Compare the character strings S1 and S2, ignoring case, returning less than,
643 equal to or greater than zero if S1 is lexicographically less than, equal to
645 Note: This function may, in multibyte locales, return 0 for strings of
647 Unlike strcasecmp(), this function works correctly in multibyte locales. */
648 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
649 _GL_ARG_NONNULL ((1, 2));
652 #if @GNULIB_MBSNCASECMP@
653 /* Compare the initial segment of the character string S1 consisting of at most
654 N characters with the initial segment of the character string S2 consisting
655 of at most N characters, ignoring case, returning less than, equal to or
656 greater than zero if the initial segment of S1 is lexicographically less
657 than, equal to or greater than the initial segment of S2.
658 Note: This function may, in multibyte locales, return 0 for initial segments
659 of different lengths!
660 Unlike strncasecmp(), this function works correctly in multibyte locales.
661 But beware that N is not a byte count but a character count! */
662 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
663 _GL_ARG_NONNULL ((1, 2));
666 #if @GNULIB_MBSPCASECMP@
667 /* Compare the initial segment of the character string STRING consisting of
668 at most mbslen (PREFIX) characters with the character string PREFIX,
669 ignoring case, returning less than, equal to or greater than zero if this
670 initial segment is lexicographically less than, equal to or greater than
672 Note: This function may, in multibyte locales, return 0 if STRING is of
673 smaller length than PREFIX!
674 Unlike strncasecmp(), this function works correctly in multibyte
676 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
677 _GL_ARG_NONNULL ((1, 2));
680 #if @GNULIB_MBSCASESTR@
681 /* Find the first occurrence of the character string NEEDLE in the character
682 string HAYSTACK, using case-insensitive comparison.
683 Note: This function may, in multibyte locales, return success even if
684 strlen (haystack) < strlen (needle) !
685 Unlike strcasestr(), this function works correctly in multibyte locales. */
686 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
687 _GL_ARG_NONNULL ((1, 2));
691 /* Find the first occurrence in the character string STRING of any character
692 in the character string ACCEPT. Return the number of bytes from the
693 beginning of the string to this occurrence, or to the end of the string
695 Unlike strcspn(), this function works correctly in multibyte locales. */
696 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
697 _GL_ARG_NONNULL ((1, 2));
701 /* Find the first occurrence in the character string STRING of any character
702 in the character string ACCEPT. Return the pointer to it, or NULL if none
704 Unlike strpbrk(), this function works correctly in multibyte locales. */
706 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
707 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
709 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
710 _GL_ARG_NONNULL ((1, 2)));
711 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
713 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
714 _GL_ARG_NONNULL ((1, 2)));
715 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
717 _GL_CXXALIASWARN (mbspbrk);
721 /* Find the first occurrence in the character string STRING of any character
722 not in the character string REJECT. Return the number of bytes from the
723 beginning of the string to this occurrence, or to the end of the string
725 Unlike strspn(), this function works correctly in multibyte locales. */
726 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
727 _GL_ARG_NONNULL ((1, 2));
731 /* Search the next delimiter (multibyte character listed in the character
732 string DELIM) starting at the character string *STRINGP.
733 If one is found, overwrite it with a NUL, and advance *STRINGP to point
734 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
735 If *STRINGP was already NULL, nothing happens.
736 Return the old value of *STRINGP.
738 This is a variant of mbstok_r() that supports empty fields.
740 Caveat: It modifies the original string.
741 Caveat: These functions cannot be used on constant strings.
742 Caveat: The identity of the delimiting character is lost.
744 See also mbstok_r(). */
745 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
746 _GL_ARG_NONNULL ((1, 2));
749 #if @GNULIB_MBSTOK_R@
750 /* Parse the character string STRING into tokens separated by characters in
751 the character string DELIM.
752 If STRING is NULL, the saved pointer in SAVE_PTR is used as
753 the next starting point. For example:
754 char s[] = "-abc-=-def";
756 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
757 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
758 x = mbstok_r(NULL, "=", &sp); // x = NULL
761 Caveat: It modifies the original string.
762 Caveat: These functions cannot be used on constant strings.
763 Caveat: The identity of the delimiting character is lost.
765 See also mbssep(). */
766 _GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr)
767 _GL_ARG_NONNULL ((2, 3));
770 /* Map any int, typically from errno, into an error message. */
771 #if @GNULIB_STRERROR@
772 # if @REPLACE_STRERROR@
773 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
775 # define strerror rpl_strerror
777 _GL_FUNCDECL_RPL (strerror, char *, (int));
778 _GL_CXXALIAS_RPL (strerror, char *, (int));
780 _GL_CXXALIAS_SYS (strerror, char *, (int));
782 _GL_CXXALIASWARN (strerror);
783 #elif defined GNULIB_POSIXCHECK
785 /* Assume strerror is always declared. */
786 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
787 "use gnulib module strerror to guarantee non-NULL result");
790 #if @GNULIB_STRSIGNAL@
791 # if @REPLACE_STRSIGNAL@
792 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
793 # define strsignal rpl_strsignal
795 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
796 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
798 # if ! @HAVE_DECL_STRSIGNAL@
799 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
801 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
803 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
805 _GL_CXXALIASWARN (strsignal);
806 #elif defined GNULIB_POSIXCHECK
808 # if HAVE_RAW_DECL_STRSIGNAL
809 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
810 "use gnulib module strsignal for portability");
814 #if @GNULIB_STRVERSCMP@
815 # if !@HAVE_STRVERSCMP@
816 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
817 _GL_ARG_NONNULL ((1, 2)));
819 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
820 _GL_CXXALIASWARN (strverscmp);
821 #elif defined GNULIB_POSIXCHECK
823 # if HAVE_RAW_DECL_STRVERSCMP
824 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
825 "use gnulib module strverscmp for portability");
830 #endif /* _GL_STRING_H */
831 #endif /* _GL_STRING_H */