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@
28 /* The include_next requires a split double-inclusion guard. */
29 #@INCLUDE_NEXT@ @NEXT_STRING_H@
34 /* NetBSD 5.0 mis-defines NULL. */
37 /* MirBSD defines mbslen as a macro. */
38 #if @GNULIB_MBSLEN@ && defined __MirBSD__
43 /* This feature is available in gcc versions 2.5 and later. */
44 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
45 # define __attribute__(Spec) /* empty */
48 /* The attribute __pure__ was added in gcc 2.96. */
49 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
50 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
52 # define _GL_ATTRIBUTE_PURE /* empty */
55 /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
56 /* But in any case avoid namespace pollution on glibc systems. */
57 #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
58 && ! defined __GLIBC__
62 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
64 /* The definition of _GL_ARG_NONNULL is copied here. */
66 /* The definition of _GL_WARN_ON_USE is copied here. */
69 /* Return the first instance of C within N bytes of S, or NULL. */
72 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
73 # define memchr rpl_memchr
75 _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
77 _GL_ARG_NONNULL ((1)));
78 _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
81 _GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
83 _GL_ARG_NONNULL ((1)));
85 /* On some systems, this function is defined as an overloaded function:
86 extern "C" { const void * std::memchr (const void *, int, size_t); }
87 extern "C++" { void * std::memchr (void *, int, size_t); } */
88 _GL_CXXALIAS_SYS_CAST2 (memchr,
89 void *, (void const *__s, int __c, size_t __n),
90 void const *, (void const *__s, int __c, size_t __n));
92 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
93 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
94 _GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
95 _GL_CXXALIASWARN1 (memchr, void const *,
96 (void const *__s, int __c, size_t __n));
98 _GL_CXXALIASWARN (memchr);
100 #elif defined GNULIB_POSIXCHECK
102 /* Assume memchr is always declared. */
103 _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
104 "use gnulib module memchr for portability" );
107 /* Return the first occurrence of NEEDLE in HAYSTACK. */
109 # if @REPLACE_MEMMEM@
110 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
111 # define memmem rpl_memmem
113 _GL_FUNCDECL_RPL (memmem, void *,
114 (void const *__haystack, size_t __haystack_len,
115 void const *__needle, size_t __needle_len)
117 _GL_ARG_NONNULL ((1, 3)));
118 _GL_CXXALIAS_RPL (memmem, void *,
119 (void const *__haystack, size_t __haystack_len,
120 void const *__needle, size_t __needle_len));
122 # if ! @HAVE_DECL_MEMMEM@
123 _GL_FUNCDECL_SYS (memmem, void *,
124 (void const *__haystack, size_t __haystack_len,
125 void const *__needle, size_t __needle_len)
127 _GL_ARG_NONNULL ((1, 3)));
129 _GL_CXXALIAS_SYS (memmem, void *,
130 (void const *__haystack, size_t __haystack_len,
131 void const *__needle, size_t __needle_len));
133 _GL_CXXALIASWARN (memmem);
134 #elif defined GNULIB_POSIXCHECK
136 # if HAVE_RAW_DECL_MEMMEM
137 _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
138 "use gnulib module memmem-simple for portability, "
139 "and module memmem for speed" );
143 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
144 last written byte. */
146 # if ! @HAVE_MEMPCPY@
147 _GL_FUNCDECL_SYS (mempcpy, void *,
148 (void *restrict __dest, void const *restrict __src,
150 _GL_ARG_NONNULL ((1, 2)));
152 _GL_CXXALIAS_SYS (mempcpy, void *,
153 (void *restrict __dest, void const *restrict __src,
155 _GL_CXXALIASWARN (mempcpy);
156 #elif defined GNULIB_POSIXCHECK
158 # if HAVE_RAW_DECL_MEMPCPY
159 _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
160 "use gnulib module mempcpy for portability");
164 /* Search backwards through a block for a byte (specified as an int). */
166 # if ! @HAVE_DECL_MEMRCHR@
167 _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
169 _GL_ARG_NONNULL ((1)));
171 /* On some systems, this function is defined as an overloaded function:
172 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
173 extern "C++" { void * std::memrchr (void *, int, size_t); } */
174 _GL_CXXALIAS_SYS_CAST2 (memrchr,
175 void *, (void const *, int, size_t),
176 void const *, (void const *, int, size_t));
177 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
178 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
179 _GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
180 _GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
182 _GL_CXXALIASWARN (memrchr);
184 #elif defined GNULIB_POSIXCHECK
186 # if HAVE_RAW_DECL_MEMRCHR
187 _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
188 "use gnulib module memrchr for portability");
192 /* Find the first occurrence of C in S. More efficient than
193 memchr(S,C,N), at the expense of undefined behavior if C does not
194 occur within N bytes. */
195 #if @GNULIB_RAWMEMCHR@
196 # if ! @HAVE_RAWMEMCHR@
197 _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
199 _GL_ARG_NONNULL ((1)));
201 /* On some systems, this function is defined as an overloaded function:
202 extern "C++" { const void * std::rawmemchr (const void *, int); }
203 extern "C++" { void * std::rawmemchr (void *, int); } */
204 _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
205 void *, (void const *__s, int __c_in),
206 void const *, (void const *__s, int __c_in));
207 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
208 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
209 _GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
210 _GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
212 _GL_CXXALIASWARN (rawmemchr);
214 #elif defined GNULIB_POSIXCHECK
216 # if HAVE_RAW_DECL_RAWMEMCHR
217 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
218 "use gnulib module rawmemchr for portability");
222 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
225 _GL_FUNCDECL_SYS (stpcpy, char *,
226 (char *restrict __dst, char const *restrict __src)
227 _GL_ARG_NONNULL ((1, 2)));
229 _GL_CXXALIAS_SYS (stpcpy, char *,
230 (char *restrict __dst, char const *restrict __src));
231 _GL_CXXALIASWARN (stpcpy);
232 #elif defined GNULIB_POSIXCHECK
234 # if HAVE_RAW_DECL_STPCPY
235 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
236 "use gnulib module stpcpy for portability");
240 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
241 last non-NUL byte written into DST. */
243 # if @REPLACE_STPNCPY@
244 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
246 # define stpncpy rpl_stpncpy
248 _GL_FUNCDECL_RPL (stpncpy, char *,
249 (char *restrict __dst, char const *restrict __src,
251 _GL_ARG_NONNULL ((1, 2)));
252 _GL_CXXALIAS_RPL (stpncpy, char *,
253 (char *restrict __dst, char const *restrict __src,
256 # if ! @HAVE_STPNCPY@
257 _GL_FUNCDECL_SYS (stpncpy, char *,
258 (char *restrict __dst, char const *restrict __src,
260 _GL_ARG_NONNULL ((1, 2)));
262 _GL_CXXALIAS_SYS (stpncpy, char *,
263 (char *restrict __dst, char const *restrict __src,
266 _GL_CXXALIASWARN (stpncpy);
267 #elif defined GNULIB_POSIXCHECK
269 # if HAVE_RAW_DECL_STPNCPY
270 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
271 "use gnulib module stpncpy for portability");
275 #if defined GNULIB_POSIXCHECK
276 /* strchr() does not work with multibyte strings if the locale encoding is
277 GB18030 and the character to be searched is a digit. */
279 /* Assume strchr is always declared. */
280 _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
281 "in some multibyte locales - "
282 "use mbschr if you care about internationalization");
285 /* Find the first occurrence of C in S or the final NUL byte. */
286 #if @GNULIB_STRCHRNUL@
287 # if ! @HAVE_STRCHRNUL@
288 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
290 _GL_ARG_NONNULL ((1)));
292 /* On some systems, this function is defined as an overloaded function:
293 extern "C++" { const char * std::strchrnul (const char *, int); }
294 extern "C++" { char * std::strchrnul (char *, int); } */
295 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
296 char *, (char const *__s, int __c_in),
297 char const *, (char const *__s, int __c_in));
298 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
299 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
300 _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
301 _GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
303 _GL_CXXALIASWARN (strchrnul);
305 #elif defined GNULIB_POSIXCHECK
307 # if HAVE_RAW_DECL_STRCHRNUL
308 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
309 "use gnulib module strchrnul for portability");
313 /* Duplicate S, returning an identical malloc'd string. */
315 # if @REPLACE_STRDUP@
316 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
318 # define strdup rpl_strdup
320 _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
321 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
323 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
324 /* strdup exists as a function and as a macro. Get rid of the macro. */
327 # if !(@HAVE_DECL_STRDUP@ || defined strdup)
328 _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
330 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
332 _GL_CXXALIASWARN (strdup);
333 #elif defined GNULIB_POSIXCHECK
335 # if HAVE_RAW_DECL_STRDUP
336 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
337 "use gnulib module strdup for portability");
341 /* Append no more than N characters from SRC onto DEST. */
343 # if @REPLACE_STRNCAT@
344 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
346 # define strncat rpl_strncat
348 _GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n)
349 _GL_ARG_NONNULL ((1, 2)));
350 _GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n));
352 _GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n));
354 _GL_CXXALIASWARN (strncat);
355 #elif defined GNULIB_POSIXCHECK
357 # if HAVE_RAW_DECL_STRNCAT
358 _GL_WARN_ON_USE (strncat, "strncat is unportable - "
359 "use gnulib module strncat for portability");
363 /* Return a newly allocated copy of at most N bytes of STRING. */
365 # if @REPLACE_STRNDUP@
366 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
368 # define strndup rpl_strndup
370 _GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n)
371 _GL_ARG_NONNULL ((1)));
372 _GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n));
374 # if ! @HAVE_DECL_STRNDUP@
375 _GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n)
376 _GL_ARG_NONNULL ((1)));
378 _GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n));
380 _GL_CXXALIASWARN (strndup);
381 #elif defined GNULIB_POSIXCHECK
383 # if HAVE_RAW_DECL_STRNDUP
384 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
385 "use gnulib module strndup for portability");
389 /* Find the length (number of bytes) of STRING, but scan at most
390 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
393 # if @REPLACE_STRNLEN@
394 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
396 # define strnlen rpl_strnlen
398 _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
400 _GL_ARG_NONNULL ((1)));
401 _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
403 # if ! @HAVE_DECL_STRNLEN@
404 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
406 _GL_ARG_NONNULL ((1)));
408 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
410 _GL_CXXALIASWARN (strnlen);
411 #elif defined GNULIB_POSIXCHECK
413 # if HAVE_RAW_DECL_STRNLEN
414 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
415 "use gnulib module strnlen for portability");
419 #if defined GNULIB_POSIXCHECK
420 /* strcspn() assumes the second argument is a list of single-byte characters.
421 Even in this simple case, it does not work with multibyte strings if the
422 locale encoding is GB18030 and one of the characters to be searched is a
425 /* Assume strcspn is always declared. */
426 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
427 "in multibyte locales - "
428 "use mbscspn if you care about internationalization");
431 /* Find the first occurrence in S of any character in ACCEPT. */
433 # if ! @HAVE_STRPBRK@
434 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
436 _GL_ARG_NONNULL ((1, 2)));
438 /* On some systems, this function is defined as an overloaded function:
439 extern "C" { const char * strpbrk (const char *, const char *); }
440 extern "C++" { char * strpbrk (char *, const char *); } */
441 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
442 char *, (char const *__s, char const *__accept),
443 const char *, (char const *__s, char const *__accept));
444 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
445 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
446 _GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
447 _GL_CXXALIASWARN1 (strpbrk, char const *,
448 (char const *__s, char const *__accept));
450 _GL_CXXALIASWARN (strpbrk);
452 # if defined GNULIB_POSIXCHECK
453 /* strpbrk() assumes the second argument is a list of single-byte characters.
454 Even in this simple case, it does not work with multibyte strings if the
455 locale encoding is GB18030 and one of the characters to be searched is a
458 _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
459 "in multibyte locales - "
460 "use mbspbrk if you care about internationalization");
462 #elif defined GNULIB_POSIXCHECK
464 # if HAVE_RAW_DECL_STRPBRK
465 _GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
466 "use gnulib module strpbrk for portability");
470 #if defined GNULIB_POSIXCHECK
471 /* strspn() assumes the second argument is a list of single-byte characters.
472 Even in this simple case, it cannot work with multibyte strings. */
474 /* Assume strspn is always declared. */
475 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
476 "in multibyte locales - "
477 "use mbsspn if you care about internationalization");
480 #if defined GNULIB_POSIXCHECK
481 /* strrchr() does not work with multibyte strings if the locale encoding is
482 GB18030 and the character to be searched is a digit. */
484 /* Assume strrchr is always declared. */
485 _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
486 "in some multibyte locales - "
487 "use mbsrchr if you care about internationalization");
490 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
491 If one is found, overwrite it with a NUL, and advance *STRINGP
492 to point to the next char after it. Otherwise, set *STRINGP to NULL.
493 If *STRINGP was already NULL, nothing happens.
494 Return the old value of *STRINGP.
496 This is a variant of strtok() that is multithread-safe and supports
499 Caveat: It modifies the original string.
500 Caveat: These functions cannot be used on constant strings.
501 Caveat: The identity of the delimiting character is lost.
502 Caveat: It doesn't work with multibyte strings unless all of the delimiter
503 characters are ASCII characters < 0x30.
505 See also strtok_r(). */
508 _GL_FUNCDECL_SYS (strsep, char *,
509 (char **restrict __stringp, char const *restrict __delim)
510 _GL_ARG_NONNULL ((1, 2)));
512 _GL_CXXALIAS_SYS (strsep, char *,
513 (char **restrict __stringp, char const *restrict __delim));
514 _GL_CXXALIASWARN (strsep);
515 # if defined GNULIB_POSIXCHECK
517 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
518 "in multibyte locales - "
519 "use mbssep if you care about internationalization");
521 #elif defined GNULIB_POSIXCHECK
523 # if HAVE_RAW_DECL_STRSEP
524 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
525 "use gnulib module strsep for portability");
530 # if @REPLACE_STRSTR@
531 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
532 # define strstr rpl_strstr
534 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
536 _GL_ARG_NONNULL ((1, 2)));
537 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
539 /* On some systems, this function is defined as an overloaded function:
540 extern "C++" { const char * strstr (const char *, const char *); }
541 extern "C++" { char * strstr (char *, const char *); } */
542 _GL_CXXALIAS_SYS_CAST2 (strstr,
543 char *, (const char *haystack, const char *needle),
544 const char *, (const char *haystack, const char *needle));
546 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
547 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
548 _GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
549 _GL_CXXALIASWARN1 (strstr, const char *,
550 (const char *haystack, const char *needle));
552 _GL_CXXALIASWARN (strstr);
554 #elif defined GNULIB_POSIXCHECK
555 /* strstr() does not work with multibyte strings if the locale encoding is
556 different from UTF-8:
557 POSIX says that it operates on "strings", and "string" in POSIX is defined
558 as a sequence of bytes, not of characters. */
560 /* Assume strstr is always declared. */
561 _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
562 "work correctly on character strings in most "
563 "multibyte locales - "
564 "use mbsstr if you care about internationalization, "
565 "or use strstr if you care about speed");
568 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
570 #if @GNULIB_STRCASESTR@
571 # if @REPLACE_STRCASESTR@
572 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
573 # define strcasestr rpl_strcasestr
575 _GL_FUNCDECL_RPL (strcasestr, char *,
576 (const char *haystack, const char *needle)
578 _GL_ARG_NONNULL ((1, 2)));
579 _GL_CXXALIAS_RPL (strcasestr, char *,
580 (const char *haystack, const char *needle));
582 # if ! @HAVE_STRCASESTR@
583 _GL_FUNCDECL_SYS (strcasestr, char *,
584 (const char *haystack, const char *needle)
586 _GL_ARG_NONNULL ((1, 2)));
588 /* On some systems, this function is defined as an overloaded function:
589 extern "C++" { const char * strcasestr (const char *, const char *); }
590 extern "C++" { char * strcasestr (char *, const char *); } */
591 _GL_CXXALIAS_SYS_CAST2 (strcasestr,
592 char *, (const char *haystack, const char *needle),
593 const char *, (const char *haystack, const char *needle));
595 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
596 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
597 _GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
598 _GL_CXXALIASWARN1 (strcasestr, const char *,
599 (const char *haystack, const char *needle));
601 _GL_CXXALIASWARN (strcasestr);
603 #elif defined GNULIB_POSIXCHECK
604 /* strcasestr() does not work with multibyte strings:
605 It is a glibc extension, and glibc implements it only for unibyte
608 # if HAVE_RAW_DECL_STRCASESTR
609 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
610 "strings in multibyte locales - "
611 "use mbscasestr if you care about "
612 "internationalization, or use c-strcasestr if you want "
613 "a locale independent function");
617 /* Parse S into tokens separated by characters in DELIM.
618 If S is NULL, the saved pointer in SAVE_PTR is used as
619 the next starting point. For example:
620 char s[] = "-abc-=-def";
622 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
623 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
624 x = strtok_r(NULL, "=", &sp); // x = NULL
627 This is a variant of strtok() that is multithread-safe.
629 For the POSIX documentation for this function, see:
630 http://www.opengroup.org/susv3xsh/strtok.html
632 Caveat: It modifies the original string.
633 Caveat: These functions cannot be used on constant strings.
634 Caveat: The identity of the delimiting character is lost.
635 Caveat: It doesn't work with multibyte strings unless all of the delimiter
636 characters are ASCII characters < 0x30.
638 See also strsep(). */
639 #if @GNULIB_STRTOK_R@
640 # if @REPLACE_STRTOK_R@
641 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
643 # define strtok_r rpl_strtok_r
645 _GL_FUNCDECL_RPL (strtok_r, char *,
646 (char *restrict s, char const *restrict delim,
647 char **restrict save_ptr)
648 _GL_ARG_NONNULL ((2, 3)));
649 _GL_CXXALIAS_RPL (strtok_r, char *,
650 (char *restrict s, char const *restrict delim,
651 char **restrict save_ptr));
653 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
656 # if ! @HAVE_DECL_STRTOK_R@
657 _GL_FUNCDECL_SYS (strtok_r, char *,
658 (char *restrict s, char const *restrict delim,
659 char **restrict save_ptr)
660 _GL_ARG_NONNULL ((2, 3)));
662 _GL_CXXALIAS_SYS (strtok_r, char *,
663 (char *restrict s, char const *restrict delim,
664 char **restrict save_ptr));
666 _GL_CXXALIASWARN (strtok_r);
667 # if defined GNULIB_POSIXCHECK
668 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
669 "strings in multibyte locales - "
670 "use mbstok_r if you care about internationalization");
672 #elif defined GNULIB_POSIXCHECK
674 # if HAVE_RAW_DECL_STRTOK_R
675 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
676 "use gnulib module strtok_r for portability");
681 /* The following functions are not specified by POSIX. They are gnulib
685 /* Return the number of multibyte characters in the character string STRING.
686 This considers multibyte characters, unlike strlen, which counts bytes. */
687 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
690 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
691 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
692 # define mbslen rpl_mbslen
694 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
695 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
697 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
698 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
700 _GL_CXXALIASWARN (mbslen);
704 /* Return the number of multibyte characters in the character string starting
705 at STRING and ending at STRING + LEN. */
706 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
707 _GL_ARG_NONNULL ((1));
711 /* Locate the first single-byte character C in the character string STRING,
712 and return a pointer to it. Return NULL if C is not found in STRING.
713 Unlike strchr(), this function works correctly in multibyte locales with
714 encodings such as GB18030. */
716 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
717 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
719 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
720 _GL_ARG_NONNULL ((1)));
721 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
723 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
724 _GL_ARG_NONNULL ((1)));
725 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
727 _GL_CXXALIASWARN (mbschr);
731 /* Locate the last single-byte character C in the character string STRING,
732 and return a pointer to it. Return NULL if C is not found in STRING.
733 Unlike strrchr(), this function works correctly in multibyte locales with
734 encodings such as GB18030. */
736 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
737 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
739 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
740 _GL_ARG_NONNULL ((1)));
741 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
743 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
744 _GL_ARG_NONNULL ((1)));
745 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
747 _GL_CXXALIASWARN (mbsrchr);
751 /* Find the first occurrence of the character string NEEDLE in the character
752 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
753 Unlike strstr(), this function works correctly in multibyte locales with
754 encodings different from UTF-8. */
755 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
756 _GL_ARG_NONNULL ((1, 2));
759 #if @GNULIB_MBSCASECMP@
760 /* Compare the character strings S1 and S2, ignoring case, returning less than,
761 equal to or greater than zero if S1 is lexicographically less than, equal to
763 Note: This function may, in multibyte locales, return 0 for strings of
765 Unlike strcasecmp(), this function works correctly in multibyte locales. */
766 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
767 _GL_ARG_NONNULL ((1, 2));
770 #if @GNULIB_MBSNCASECMP@
771 /* Compare the initial segment of the character string S1 consisting of at most
772 N characters with the initial segment of the character string S2 consisting
773 of at most N characters, ignoring case, returning less than, equal to or
774 greater than zero if the initial segment of S1 is lexicographically less
775 than, equal to or greater than the initial segment of S2.
776 Note: This function may, in multibyte locales, return 0 for initial segments
777 of different lengths!
778 Unlike strncasecmp(), this function works correctly in multibyte locales.
779 But beware that N is not a byte count but a character count! */
780 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
781 _GL_ARG_NONNULL ((1, 2));
784 #if @GNULIB_MBSPCASECMP@
785 /* Compare the initial segment of the character string STRING consisting of
786 at most mbslen (PREFIX) characters with the character string PREFIX,
787 ignoring case. If the two match, return a pointer to the first byte
788 after this prefix in STRING. Otherwise, return NULL.
789 Note: This function may, in multibyte locales, return non-NULL if STRING
790 is of smaller length than PREFIX!
791 Unlike strncasecmp(), this function works correctly in multibyte
793 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
794 _GL_ARG_NONNULL ((1, 2));
797 #if @GNULIB_MBSCASESTR@
798 /* Find the first occurrence of the character string NEEDLE in the character
799 string HAYSTACK, using case-insensitive comparison.
800 Note: This function may, in multibyte locales, return success even if
801 strlen (haystack) < strlen (needle) !
802 Unlike strcasestr(), this function works correctly in multibyte locales. */
803 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
804 _GL_ARG_NONNULL ((1, 2));
808 /* Find the first occurrence in the character string STRING of any character
809 in the character string ACCEPT. Return the number of bytes from the
810 beginning of the string to this occurrence, or to the end of the string
812 Unlike strcspn(), this function works correctly in multibyte locales. */
813 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
814 _GL_ARG_NONNULL ((1, 2));
818 /* Find the first occurrence in the character string STRING of any character
819 in the character string ACCEPT. Return the pointer to it, or NULL if none
821 Unlike strpbrk(), this function works correctly in multibyte locales. */
823 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
824 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
826 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
827 _GL_ARG_NONNULL ((1, 2)));
828 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
830 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
831 _GL_ARG_NONNULL ((1, 2)));
832 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
834 _GL_CXXALIASWARN (mbspbrk);
838 /* Find the first occurrence in the character string STRING of any character
839 not in the character string REJECT. Return the number of bytes from the
840 beginning of the string to this occurrence, or to the end of the string
842 Unlike strspn(), this function works correctly in multibyte locales. */
843 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
844 _GL_ARG_NONNULL ((1, 2));
848 /* Search the next delimiter (multibyte character listed in the character
849 string DELIM) starting at the character string *STRINGP.
850 If one is found, overwrite it with a NUL, and advance *STRINGP to point
851 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
852 If *STRINGP was already NULL, nothing happens.
853 Return the old value of *STRINGP.
855 This is a variant of mbstok_r() that supports empty fields.
857 Caveat: It modifies the original string.
858 Caveat: These functions cannot be used on constant strings.
859 Caveat: The identity of the delimiting character is lost.
861 See also mbstok_r(). */
862 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
863 _GL_ARG_NONNULL ((1, 2));
866 #if @GNULIB_MBSTOK_R@
867 /* Parse the character string STRING into tokens separated by characters in
868 the character string DELIM.
869 If STRING is NULL, the saved pointer in SAVE_PTR is used as
870 the next starting point. For example:
871 char s[] = "-abc-=-def";
873 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
874 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
875 x = mbstok_r(NULL, "=", &sp); // x = NULL
878 Caveat: It modifies the original string.
879 Caveat: These functions cannot be used on constant strings.
880 Caveat: The identity of the delimiting character is lost.
882 See also mbssep(). */
883 _GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr)
884 _GL_ARG_NONNULL ((2, 3));
887 /* Map any int, typically from errno, into an error message. */
888 #if @GNULIB_STRERROR@
889 # if @REPLACE_STRERROR@
890 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
892 # define strerror rpl_strerror
894 _GL_FUNCDECL_RPL (strerror, char *, (int));
895 _GL_CXXALIAS_RPL (strerror, char *, (int));
897 _GL_CXXALIAS_SYS (strerror, char *, (int));
899 _GL_CXXALIASWARN (strerror);
900 #elif defined GNULIB_POSIXCHECK
902 /* Assume strerror is always declared. */
903 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
904 "use gnulib module strerror to guarantee non-NULL result");
907 #if @GNULIB_STRSIGNAL@
908 # if @REPLACE_STRSIGNAL@
909 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
910 # define strsignal rpl_strsignal
912 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
913 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
915 # if ! @HAVE_DECL_STRSIGNAL@
916 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
918 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
920 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
922 _GL_CXXALIASWARN (strsignal);
923 #elif defined GNULIB_POSIXCHECK
925 # if HAVE_RAW_DECL_STRSIGNAL
926 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
927 "use gnulib module strsignal for portability");
931 #if @GNULIB_STRVERSCMP@
932 # if !@HAVE_STRVERSCMP@
933 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
934 _GL_ARG_NONNULL ((1, 2)));
936 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
937 _GL_CXXALIASWARN (strverscmp);
938 #elif defined GNULIB_POSIXCHECK
940 # if HAVE_RAW_DECL_STRVERSCMP
941 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
942 "use gnulib module strverscmp for portability");
947 #endif /* _GL_STRING_H */
948 #endif /* _GL_STRING_H */