1 /* A GNU-like <string.h>.
3 Copyright (C) 1995-1996, 2001-2010 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 @PRAGMA_SYSTEM_HEADER@
25 /* The include_next requires a split double-inclusion guard. */
26 #@INCLUDE_NEXT@ @NEXT_STRING_H@
31 /* NetBSD 5.0 mis-defines NULL. */
34 /* MirBSD defines mbslen as a macro. */
35 #if @GNULIB_MBSLEN@ && defined __MirBSD__
40 /* This feature is available in gcc versions 2.5 and later. */
41 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
42 # define __attribute__(Spec) /* empty */
44 /* The attribute __pure__ was added in gcc 2.96. */
45 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
46 # define __pure__ /* empty */
51 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
53 /* The definition of _GL_ARG_NONNULL is copied here. */
55 /* The definition of _GL_WARN_ON_USE is copied here. */
58 /* Return the first instance of C within N bytes of S, or NULL. */
61 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
62 # define memchr rpl_memchr
64 _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
65 __attribute__ ((__pure__))
66 _GL_ARG_NONNULL ((1)));
67 _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
69 # if defined __SUNPRO_CC
70 /* This compiler defines an overloaded function
71 extern "C" { const void * std::memchr (const void *, int, size_t); }
72 extern "C++" { inline void * std::memchr (void *, int, size_t); }
73 and diagnoses an error
74 "Error: Could not find a match for std::memchr(const void*, int, unsigned)"
76 _GL_CXXALIAS_SYS_CAST2 (memchr,
77 void *, (void const *__s, int __c, size_t __n),
78 void const *, (void const *__s, int __c, size_t __n));
80 _GL_CXXALIAS_SYS (memchr, void *, (void const *__s, int __c, size_t __n));
83 _GL_CXXALIASWARN (memchr);
84 #elif defined GNULIB_POSIXCHECK
86 /* Assume memchr is always declared. */
87 _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
88 "use gnulib module memchr for portability" );
91 /* Return the first occurrence of NEEDLE in HAYSTACK. */
94 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
95 # define memmem rpl_memmem
97 _GL_FUNCDECL_RPL (memmem, void *,
98 (void const *__haystack, size_t __haystack_len,
99 void const *__needle, size_t __needle_len)
100 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
101 _GL_CXXALIAS_RPL (memmem, void *,
102 (void const *__haystack, size_t __haystack_len,
103 void const *__needle, size_t __needle_len));
105 # if ! @HAVE_DECL_MEMMEM@
106 _GL_FUNCDECL_SYS (memmem, void *,
107 (void const *__haystack, size_t __haystack_len,
108 void const *__needle, size_t __needle_len)
109 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3)));
111 _GL_CXXALIAS_SYS (memmem, void *,
112 (void const *__haystack, size_t __haystack_len,
113 void const *__needle, size_t __needle_len));
115 _GL_CXXALIASWARN (memmem);
116 #elif defined GNULIB_POSIXCHECK
118 # if HAVE_RAW_DECL_MEMMEM
119 _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
120 "use gnulib module memmem-simple for portability, "
121 "and module memmem for speed" );
125 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
126 last written byte. */
128 # if ! @HAVE_MEMPCPY@
129 _GL_FUNCDECL_SYS (mempcpy, void *,
130 (void *restrict __dest, void const *restrict __src,
132 _GL_ARG_NONNULL ((1, 2)));
134 _GL_CXXALIAS_SYS (mempcpy, void *,
135 (void *restrict __dest, void const *restrict __src,
137 _GL_CXXALIASWARN (mempcpy);
138 #elif defined GNULIB_POSIXCHECK
140 # if HAVE_RAW_DECL_MEMPCPY
141 _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
142 "use gnulib module mempcpy for portability");
146 /* Search backwards through a block for a byte (specified as an int). */
148 # if ! @HAVE_DECL_MEMRCHR@
149 _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
150 __attribute__ ((__pure__))
151 _GL_ARG_NONNULL ((1)));
153 _GL_CXXALIAS_SYS (memrchr, void *, (void const *, int, size_t));
154 _GL_CXXALIASWARN (memrchr);
155 #elif defined GNULIB_POSIXCHECK
157 # if HAVE_RAW_DECL_MEMRCHR
158 _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
159 "use gnulib module memrchr for portability");
163 /* Find the first occurrence of C in S. More efficient than
164 memchr(S,C,N), at the expense of undefined behavior if C does not
165 occur within N bytes. */
166 #if @GNULIB_RAWMEMCHR@
167 # if ! @HAVE_RAWMEMCHR@
168 _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
169 __attribute__ ((__pure__))
170 _GL_ARG_NONNULL ((1)));
172 _GL_CXXALIAS_SYS (rawmemchr, void *, (void const *__s, int __c_in));
173 _GL_CXXALIASWARN (rawmemchr);
174 #elif defined GNULIB_POSIXCHECK
176 # if HAVE_RAW_DECL_RAWMEMCHR
177 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
178 "use gnulib module rawmemchr for portability");
182 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
185 _GL_FUNCDECL_SYS (stpcpy, char *,
186 (char *restrict __dst, char const *restrict __src)
187 _GL_ARG_NONNULL ((1, 2)));
189 _GL_CXXALIAS_SYS (stpcpy, char *,
190 (char *restrict __dst, char const *restrict __src));
191 _GL_CXXALIASWARN (stpcpy);
192 #elif defined GNULIB_POSIXCHECK
194 # if HAVE_RAW_DECL_STPCPY
195 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
196 "use gnulib module stpcpy for portability");
200 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
201 last non-NUL byte written into DST. */
203 # if ! @HAVE_STPNCPY@
204 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
205 # define stpncpy rpl_stpncpy
207 _GL_FUNCDECL_RPL (stpncpy, char *,
208 (char *restrict __dst, char const *restrict __src,
210 _GL_ARG_NONNULL ((1, 2)));
211 _GL_CXXALIAS_RPL (stpncpy, char *,
212 (char *restrict __dst, char const *restrict __src,
215 _GL_CXXALIAS_SYS (stpncpy, char *,
216 (char *restrict __dst, char const *restrict __src,
219 _GL_CXXALIASWARN (stpncpy);
220 #elif defined GNULIB_POSIXCHECK
222 # if HAVE_RAW_DECL_STPNCPY
223 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
224 "use gnulib module stpncpy for portability");
228 #if defined GNULIB_POSIXCHECK
229 /* strchr() does not work with multibyte strings if the locale encoding is
230 GB18030 and the character to be searched is a digit. */
232 /* Assume strchr is always declared. */
233 _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
234 "in some multibyte locales - "
235 "use mbschr if you care about internationalization");
238 /* Find the first occurrence of C in S or the final NUL byte. */
239 #if @GNULIB_STRCHRNUL@
240 # if ! @HAVE_STRCHRNUL@
241 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
242 __attribute__ ((__pure__))
243 _GL_ARG_NONNULL ((1)));
245 _GL_CXXALIAS_SYS (strchrnul, char *, (char const *__s, int __c_in));
246 _GL_CXXALIASWARN (strchrnul);
247 #elif defined GNULIB_POSIXCHECK
249 # if HAVE_RAW_DECL_STRCHRNUL
250 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
251 "use gnulib module strchrnul for portability");
255 /* Duplicate S, returning an identical malloc'd string. */
257 # if @REPLACE_STRDUP@
258 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
260 # define strdup rpl_strdup
262 _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
263 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
265 # if !(@HAVE_DECL_STRDUP@ || defined strdup)
266 _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
268 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
270 _GL_CXXALIASWARN (strdup);
271 #elif defined GNULIB_POSIXCHECK
273 # if HAVE_RAW_DECL_STRDUP
274 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
275 "use gnulib module strdup for portability");
279 /* Return a newly allocated copy of at most N bytes of STRING. */
281 # if @REPLACE_STRNDUP@
282 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
284 # define strndup rpl_strndup
286 _GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n)
287 _GL_ARG_NONNULL ((1)));
288 _GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n));
290 # if ! @HAVE_DECL_STRNDUP@
291 _GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n)
292 _GL_ARG_NONNULL ((1)));
294 _GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n));
296 _GL_CXXALIASWARN (strndup);
297 #elif defined GNULIB_POSIXCHECK
299 # if HAVE_RAW_DECL_STRNDUP
300 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
301 "use gnulib module strndup for portability");
305 /* Find the length (number of bytes) of STRING, but scan at most
306 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
309 # if ! @HAVE_DECL_STRNLEN@
310 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
311 __attribute__ ((__pure__))
312 _GL_ARG_NONNULL ((1)));
314 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
315 _GL_CXXALIASWARN (strnlen);
316 #elif defined GNULIB_POSIXCHECK
318 # if HAVE_RAW_DECL_STRNLEN
319 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
320 "use gnulib module strnlen for portability");
324 #if defined GNULIB_POSIXCHECK
325 /* strcspn() assumes the second argument is a list of single-byte characters.
326 Even in this simple case, it does not work with multibyte strings if the
327 locale encoding is GB18030 and one of the characters to be searched is a
330 /* Assume strcspn is always declared. */
331 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
332 "in multibyte locales - "
333 "use mbscspn if you care about internationalization");
336 /* Find the first occurrence in S of any character in ACCEPT. */
338 # if ! @HAVE_STRPBRK@
339 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
340 __attribute__ ((__pure__))
341 _GL_ARG_NONNULL ((1, 2)));
343 # if defined __SUNPRO_CC
344 /* This compiler defines an overloaded function
345 extern "C" { const char * strpbrk (const char *, const char *); }
346 extern "C++" { inline char * strpbrk (char *, const char *); }
347 and diagnoses an error
348 "Error: Could not find a match for std::strpbrk(const char*, const char*)"
350 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
351 char *, (char const *__s, char const *__accept),
352 const char *, (char const *__s, char const *__accept));
354 _GL_CXXALIAS_SYS (strpbrk, char *, (char const *__s, char const *__accept));
356 _GL_CXXALIASWARN (strpbrk);
357 # if defined GNULIB_POSIXCHECK
358 /* strpbrk() assumes the second argument is a list of single-byte characters.
359 Even in this simple case, it does not work with multibyte strings if the
360 locale encoding is GB18030 and one of the characters to be searched is a
363 _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
364 "in multibyte locales - "
365 "use mbspbrk if you care about internationalization");
367 #elif defined GNULIB_POSIXCHECK
369 # if HAVE_RAW_DECL_STRPBRK
370 _GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
371 "use gnulib module strpbrk for portability");
375 #if defined GNULIB_POSIXCHECK
376 /* strspn() assumes the second argument is a list of single-byte characters.
377 Even in this simple case, it cannot work with multibyte strings. */
379 /* Assume strspn is always declared. */
380 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
381 "in multibyte locales - "
382 "use mbsspn if you care about internationalization");
385 #if defined GNULIB_POSIXCHECK
386 /* strrchr() does not work with multibyte strings if the locale encoding is
387 GB18030 and the character to be searched is a digit. */
389 /* Assume strrchr is always declared. */
390 _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
391 "in some multibyte locales - "
392 "use mbsrchr if you care about internationalization");
395 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
396 If one is found, overwrite it with a NUL, and advance *STRINGP
397 to point to the next char after it. Otherwise, set *STRINGP to NULL.
398 If *STRINGP was already NULL, nothing happens.
399 Return the old value of *STRINGP.
401 This is a variant of strtok() that is multithread-safe and supports
404 Caveat: It modifies the original string.
405 Caveat: These functions cannot be used on constant strings.
406 Caveat: The identity of the delimiting character is lost.
407 Caveat: It doesn't work with multibyte strings unless all of the delimiter
408 characters are ASCII characters < 0x30.
410 See also strtok_r(). */
413 _GL_FUNCDECL_SYS (strsep, char *,
414 (char **restrict __stringp, char const *restrict __delim)
415 _GL_ARG_NONNULL ((1, 2)));
417 _GL_CXXALIAS_SYS (strsep, char *,
418 (char **restrict __stringp, char const *restrict __delim));
419 _GL_CXXALIASWARN (strsep);
420 # if defined GNULIB_POSIXCHECK
422 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
423 "in multibyte locales - "
424 "use mbssep if you care about internationalization");
426 #elif defined GNULIB_POSIXCHECK
428 # if HAVE_RAW_DECL_STRSEP
429 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
430 "use gnulib module strsep for portability");
435 # if @REPLACE_STRSTR@
436 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
437 # define strstr rpl_strstr
439 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
440 __attribute__ ((__pure__))
441 _GL_ARG_NONNULL ((1, 2)));
442 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
444 _GL_CXXALIAS_SYS (strstr, char *, (const char *haystack, const char *needle));
446 _GL_CXXALIASWARN (strstr);
447 #elif defined GNULIB_POSIXCHECK
448 /* strstr() does not work with multibyte strings if the locale encoding is
449 different from UTF-8:
450 POSIX says that it operates on "strings", and "string" in POSIX is defined
451 as a sequence of bytes, not of characters. */
453 /* Assume strstr is always declared. */
454 _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
455 "work correctly on character strings in most "
456 "multibyte locales - "
457 "use mbsstr if you care about internationalization, "
458 "or use strstr if you care about speed");
461 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
463 #if @GNULIB_STRCASESTR@
464 # if @REPLACE_STRCASESTR@
465 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
466 # define strcasestr rpl_strcasestr
468 _GL_FUNCDECL_RPL (strcasestr, char *,
469 (const char *haystack, const char *needle)
470 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
471 _GL_CXXALIAS_RPL (strcasestr, char *,
472 (const char *haystack, const char *needle));
474 # if ! @HAVE_STRCASESTR@
475 _GL_FUNCDECL_SYS (strcasestr, char *,
476 (const char *haystack, const char *needle)
477 __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2)));
479 _GL_CXXALIAS_SYS (strcasestr, char *,
480 (const char *haystack, const char *needle));
482 _GL_CXXALIASWARN (strcasestr);
483 #elif defined GNULIB_POSIXCHECK
484 /* strcasestr() does not work with multibyte strings:
485 It is a glibc extension, and glibc implements it only for unibyte
488 # if HAVE_RAW_DECL_STRCASESTR
489 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
490 "strings in multibyte locales - "
491 "use mbscasestr if you care about "
492 "internationalization, or use c-strcasestr if you want "
493 "a locale independent function");
497 /* Parse S into tokens separated by characters in DELIM.
498 If S is NULL, the saved pointer in SAVE_PTR is used as
499 the next starting point. For example:
500 char s[] = "-abc-=-def";
502 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
503 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
504 x = strtok_r(NULL, "=", &sp); // x = NULL
507 This is a variant of strtok() that is multithread-safe.
509 For the POSIX documentation for this function, see:
510 http://www.opengroup.org/susv3xsh/strtok.html
512 Caveat: It modifies the original string.
513 Caveat: These functions cannot be used on constant strings.
514 Caveat: The identity of the delimiting character is lost.
515 Caveat: It doesn't work with multibyte strings unless all of the delimiter
516 characters are ASCII characters < 0x30.
518 See also strsep(). */
519 #if @GNULIB_STRTOK_R@
520 # if @REPLACE_STRTOK_R@
521 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
523 # define strtok_r rpl_strtok_r
525 _GL_FUNCDECL_RPL (strtok_r, char *,
526 (char *restrict s, char const *restrict delim,
527 char **restrict save_ptr)
528 _GL_ARG_NONNULL ((2, 3)));
529 _GL_CXXALIAS_RPL (strtok_r, char *,
530 (char *restrict s, char const *restrict delim,
531 char **restrict save_ptr));
533 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
536 # if ! @HAVE_DECL_STRTOK_R@
537 _GL_FUNCDECL_SYS (strtok_r, char *,
538 (char *restrict s, char const *restrict delim,
539 char **restrict save_ptr)
540 _GL_ARG_NONNULL ((2, 3)));
542 _GL_CXXALIAS_SYS (strtok_r, char *,
543 (char *restrict s, char const *restrict delim,
544 char **restrict save_ptr));
546 _GL_CXXALIASWARN (strtok_r);
547 # if defined GNULIB_POSIXCHECK
548 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
549 "strings in multibyte locales - "
550 "use mbstok_r if you care about internationalization");
552 #elif defined GNULIB_POSIXCHECK
554 # if HAVE_RAW_DECL_STRTOK_R
555 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
556 "use gnulib module strtok_r for portability");
561 /* The following functions are not specified by POSIX. They are gnulib
565 /* Return the number of multibyte characters in the character string STRING.
566 This considers multibyte characters, unlike strlen, which counts bytes. */
567 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
570 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
571 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
572 # define mbslen rpl_mbslen
574 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
575 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
577 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
578 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
580 _GL_CXXALIASWARN (mbslen);
584 /* Return the number of multibyte characters in the character string starting
585 at STRING and ending at STRING + LEN. */
586 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
587 _GL_ARG_NONNULL ((1));
591 /* Locate the first single-byte character C in the character string STRING,
592 and return a pointer to it. Return NULL if C is not found in STRING.
593 Unlike strchr(), this function works correctly in multibyte locales with
594 encodings such as GB18030. */
596 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
597 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
599 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
600 _GL_ARG_NONNULL ((1)));
601 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
603 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
604 _GL_ARG_NONNULL ((1)));
605 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
607 _GL_CXXALIASWARN (mbschr);
611 /* Locate the last single-byte character C in the character string STRING,
612 and return a pointer to it. Return NULL if C is not found in STRING.
613 Unlike strrchr(), this function works correctly in multibyte locales with
614 encodings such as GB18030. */
616 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
617 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
619 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
620 _GL_ARG_NONNULL ((1)));
621 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
623 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
624 _GL_ARG_NONNULL ((1)));
625 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
627 _GL_CXXALIASWARN (mbsrchr);
631 /* Find the first occurrence of the character string NEEDLE in the character
632 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
633 Unlike strstr(), this function works correctly in multibyte locales with
634 encodings different from UTF-8. */
635 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
636 _GL_ARG_NONNULL ((1, 2));
639 #if @GNULIB_MBSCASECMP@
640 /* Compare the character strings S1 and S2, ignoring case, returning less than,
641 equal to or greater than zero if S1 is lexicographically less than, equal to
643 Note: This function may, in multibyte locales, return 0 for strings of
645 Unlike strcasecmp(), this function works correctly in multibyte locales. */
646 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
647 _GL_ARG_NONNULL ((1, 2));
650 #if @GNULIB_MBSNCASECMP@
651 /* Compare the initial segment of the character string S1 consisting of at most
652 N characters with the initial segment of the character string S2 consisting
653 of at most N characters, ignoring case, returning less than, equal to or
654 greater than zero if the initial segment of S1 is lexicographically less
655 than, equal to or greater than the initial segment of S2.
656 Note: This function may, in multibyte locales, return 0 for initial segments
657 of different lengths!
658 Unlike strncasecmp(), this function works correctly in multibyte locales.
659 But beware that N is not a byte count but a character count! */
660 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
661 _GL_ARG_NONNULL ((1, 2));
664 #if @GNULIB_MBSPCASECMP@
665 /* Compare the initial segment of the character string STRING consisting of
666 at most mbslen (PREFIX) characters with the character string PREFIX,
667 ignoring case, returning less than, equal to or greater than zero if this
668 initial segment is lexicographically less than, equal to or greater than
670 Note: This function may, in multibyte locales, return 0 if STRING is of
671 smaller length than PREFIX!
672 Unlike strncasecmp(), this function works correctly in multibyte
674 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
675 _GL_ARG_NONNULL ((1, 2));
678 #if @GNULIB_MBSCASESTR@
679 /* Find the first occurrence of the character string NEEDLE in the character
680 string HAYSTACK, using case-insensitive comparison.
681 Note: This function may, in multibyte locales, return success even if
682 strlen (haystack) < strlen (needle) !
683 Unlike strcasestr(), this function works correctly in multibyte locales. */
684 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
685 _GL_ARG_NONNULL ((1, 2));
689 /* Find the first occurrence in the character string STRING of any character
690 in the character string ACCEPT. Return the number of bytes from the
691 beginning of the string to this occurrence, or to the end of the string
693 Unlike strcspn(), this function works correctly in multibyte locales. */
694 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
695 _GL_ARG_NONNULL ((1, 2));
699 /* Find the first occurrence in the character string STRING of any character
700 in the character string ACCEPT. Return the pointer to it, or NULL if none
702 Unlike strpbrk(), this function works correctly in multibyte locales. */
704 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
705 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
707 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
708 _GL_ARG_NONNULL ((1, 2)));
709 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
711 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
712 _GL_ARG_NONNULL ((1, 2)));
713 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
715 _GL_CXXALIASWARN (mbspbrk);
719 /* Find the first occurrence in the character string STRING of any character
720 not in the character string REJECT. Return the number of bytes from the
721 beginning of the string to this occurrence, or to the end of the string
723 Unlike strspn(), this function works correctly in multibyte locales. */
724 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
725 _GL_ARG_NONNULL ((1, 2));
729 /* Search the next delimiter (multibyte character listed in the character
730 string DELIM) starting at the character string *STRINGP.
731 If one is found, overwrite it with a NUL, and advance *STRINGP to point
732 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
733 If *STRINGP was already NULL, nothing happens.
734 Return the old value of *STRINGP.
736 This is a variant of mbstok_r() that supports empty fields.
738 Caveat: It modifies the original string.
739 Caveat: These functions cannot be used on constant strings.
740 Caveat: The identity of the delimiting character is lost.
742 See also mbstok_r(). */
743 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
744 _GL_ARG_NONNULL ((1, 2));
747 #if @GNULIB_MBSTOK_R@
748 /* Parse the character string STRING into tokens separated by characters in
749 the character string DELIM.
750 If STRING is NULL, the saved pointer in SAVE_PTR is used as
751 the next starting point. For example:
752 char s[] = "-abc-=-def";
754 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
755 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
756 x = mbstok_r(NULL, "=", &sp); // x = NULL
759 Caveat: It modifies the original string.
760 Caveat: These functions cannot be used on constant strings.
761 Caveat: The identity of the delimiting character is lost.
763 See also mbssep(). */
764 _GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr)
765 _GL_ARG_NONNULL ((2, 3));
768 /* Map any int, typically from errno, into an error message. */
769 #if @GNULIB_STRERROR@
770 # if @REPLACE_STRERROR@
771 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
773 # define strerror rpl_strerror
775 _GL_FUNCDECL_RPL (strerror, char *, (int));
776 _GL_CXXALIAS_RPL (strerror, char *, (int));
778 _GL_CXXALIAS_SYS (strerror, char *, (int));
780 _GL_CXXALIASWARN (strerror);
781 #elif defined GNULIB_POSIXCHECK
783 /* Assume strerror is always declared. */
784 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
785 "use gnulib module strerror to guarantee non-NULL result");
788 #if @GNULIB_STRSIGNAL@
789 # if @REPLACE_STRSIGNAL@
790 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
791 # define strsignal rpl_strsignal
793 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
794 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
796 # if ! @HAVE_DECL_STRSIGNAL@
797 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
799 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
801 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
803 _GL_CXXALIASWARN (strsignal);
804 #elif defined GNULIB_POSIXCHECK
806 # if HAVE_RAW_DECL_STRSIGNAL
807 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
808 "use gnulib module strsignal for portability");
812 #if @GNULIB_STRVERSCMP@
813 # if !@HAVE_STRVERSCMP@
814 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
815 _GL_ARG_NONNULL ((1, 2)));
817 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
818 _GL_CXXALIASWARN (strverscmp);
819 #elif defined GNULIB_POSIXCHECK
821 # if HAVE_RAW_DECL_STRVERSCMP
822 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
823 "use gnulib module strverscmp for portability");
828 #endif /* _GL_STRING_H */
829 #endif /* _GL_STRING_H */