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-2013 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, see <http://www.gnu.org/licenses/>. */
20 #ifndef _@GUARD_PREFIX@_STRING_H
23 @PRAGMA_SYSTEM_HEADER@
27 /* The include_next requires a split double-inclusion guard. */
28 #@INCLUDE_NEXT@ @NEXT_STRING_H@
30 #ifndef _@GUARD_PREFIX@_STRING_H
31 #define _@GUARD_PREFIX@_STRING_H
33 /* NetBSD 5.0 mis-defines NULL. */
36 /* MirBSD defines mbslen as a macro. */
37 #if @GNULIB_MBSLEN@ && defined __MirBSD__
41 /* The __attribute__ feature is available in gcc versions 2.5 and later.
42 The attribute __pure__ was added in gcc 2.96. */
43 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
44 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
46 # define _GL_ATTRIBUTE_PURE /* empty */
49 /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
50 /* But in any case avoid namespace pollution on glibc systems. */
51 #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
52 && ! defined __GLIBC__
56 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
58 /* The definition of _GL_ARG_NONNULL is copied here. */
60 /* The definition of _GL_WARN_ON_USE is copied here. */
63 /* Find the index of the least-significant set bit. */
66 _GL_FUNCDECL_SYS (ffsl, int, (long int i));
68 _GL_CXXALIAS_SYS (ffsl, int, (long int i));
69 _GL_CXXALIASWARN (ffsl);
70 #elif defined GNULIB_POSIXCHECK
72 # if HAVE_RAW_DECL_FFSL
73 _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
78 /* Find the index of the least-significant set bit. */
81 _GL_FUNCDECL_SYS (ffsll, int, (long long int i));
83 _GL_CXXALIAS_SYS (ffsll, int, (long long int i));
84 _GL_CXXALIASWARN (ffsll);
85 #elif defined GNULIB_POSIXCHECK
87 # if HAVE_RAW_DECL_FFSLL
88 _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
93 /* Return the first instance of C within N bytes of S, or NULL. */
96 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
97 # define memchr rpl_memchr
99 _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
101 _GL_ARG_NONNULL ((1)));
102 _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
105 _GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
107 _GL_ARG_NONNULL ((1)));
109 /* On some systems, this function is defined as an overloaded function:
110 extern "C" { const void * std::memchr (const void *, int, size_t); }
111 extern "C++" { void * std::memchr (void *, int, size_t); } */
112 _GL_CXXALIAS_SYS_CAST2 (memchr,
113 void *, (void const *__s, int __c, size_t __n),
114 void const *, (void const *__s, int __c, size_t __n));
116 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
117 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
118 _GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
119 _GL_CXXALIASWARN1 (memchr, void const *,
120 (void const *__s, int __c, size_t __n));
122 _GL_CXXALIASWARN (memchr);
124 #elif defined GNULIB_POSIXCHECK
126 /* Assume memchr is always declared. */
127 _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
128 "use gnulib module memchr for portability" );
131 /* Return the first occurrence of NEEDLE in HAYSTACK. */
133 # if @REPLACE_MEMMEM@
134 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
135 # define memmem rpl_memmem
137 _GL_FUNCDECL_RPL (memmem, void *,
138 (void const *__haystack, size_t __haystack_len,
139 void const *__needle, size_t __needle_len)
141 _GL_ARG_NONNULL ((1, 3)));
142 _GL_CXXALIAS_RPL (memmem, void *,
143 (void const *__haystack, size_t __haystack_len,
144 void const *__needle, size_t __needle_len));
146 # if ! @HAVE_DECL_MEMMEM@
147 _GL_FUNCDECL_SYS (memmem, void *,
148 (void const *__haystack, size_t __haystack_len,
149 void const *__needle, size_t __needle_len)
151 _GL_ARG_NONNULL ((1, 3)));
153 _GL_CXXALIAS_SYS (memmem, void *,
154 (void const *__haystack, size_t __haystack_len,
155 void const *__needle, size_t __needle_len));
157 _GL_CXXALIASWARN (memmem);
158 #elif defined GNULIB_POSIXCHECK
160 # if HAVE_RAW_DECL_MEMMEM
161 _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
162 "use gnulib module memmem-simple for portability, "
163 "and module memmem for speed" );
167 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
168 last written byte. */
170 # if ! @HAVE_MEMPCPY@
171 _GL_FUNCDECL_SYS (mempcpy, void *,
172 (void *restrict __dest, void const *restrict __src,
174 _GL_ARG_NONNULL ((1, 2)));
176 _GL_CXXALIAS_SYS (mempcpy, void *,
177 (void *restrict __dest, void const *restrict __src,
179 _GL_CXXALIASWARN (mempcpy);
180 #elif defined GNULIB_POSIXCHECK
182 # if HAVE_RAW_DECL_MEMPCPY
183 _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
184 "use gnulib module mempcpy for portability");
188 /* Search backwards through a block for a byte (specified as an int). */
190 # if ! @HAVE_DECL_MEMRCHR@
191 _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
193 _GL_ARG_NONNULL ((1)));
195 /* On some systems, this function is defined as an overloaded function:
196 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
197 extern "C++" { void * std::memrchr (void *, int, size_t); } */
198 _GL_CXXALIAS_SYS_CAST2 (memrchr,
199 void *, (void const *, int, size_t),
200 void const *, (void const *, int, size_t));
201 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
202 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
203 _GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
204 _GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
206 _GL_CXXALIASWARN (memrchr);
208 #elif defined GNULIB_POSIXCHECK
210 # if HAVE_RAW_DECL_MEMRCHR
211 _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
212 "use gnulib module memrchr for portability");
216 /* Find the first occurrence of C in S. More efficient than
217 memchr(S,C,N), at the expense of undefined behavior if C does not
218 occur within N bytes. */
219 #if @GNULIB_RAWMEMCHR@
220 # if ! @HAVE_RAWMEMCHR@
221 _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
223 _GL_ARG_NONNULL ((1)));
225 /* On some systems, this function is defined as an overloaded function:
226 extern "C++" { const void * std::rawmemchr (const void *, int); }
227 extern "C++" { void * std::rawmemchr (void *, int); } */
228 _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
229 void *, (void const *__s, int __c_in),
230 void const *, (void const *__s, int __c_in));
231 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
232 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
233 _GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
234 _GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
236 _GL_CXXALIASWARN (rawmemchr);
238 #elif defined GNULIB_POSIXCHECK
240 # if HAVE_RAW_DECL_RAWMEMCHR
241 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
242 "use gnulib module rawmemchr for portability");
246 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
249 _GL_FUNCDECL_SYS (stpcpy, char *,
250 (char *restrict __dst, char const *restrict __src)
251 _GL_ARG_NONNULL ((1, 2)));
253 _GL_CXXALIAS_SYS (stpcpy, char *,
254 (char *restrict __dst, char const *restrict __src));
255 _GL_CXXALIASWARN (stpcpy);
256 #elif defined GNULIB_POSIXCHECK
258 # if HAVE_RAW_DECL_STPCPY
259 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
260 "use gnulib module stpcpy for portability");
264 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
265 last non-NUL byte written into DST. */
267 # if @REPLACE_STPNCPY@
268 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
270 # define stpncpy rpl_stpncpy
272 _GL_FUNCDECL_RPL (stpncpy, char *,
273 (char *restrict __dst, char const *restrict __src,
275 _GL_ARG_NONNULL ((1, 2)));
276 _GL_CXXALIAS_RPL (stpncpy, char *,
277 (char *restrict __dst, char const *restrict __src,
280 # if ! @HAVE_STPNCPY@
281 _GL_FUNCDECL_SYS (stpncpy, char *,
282 (char *restrict __dst, char const *restrict __src,
284 _GL_ARG_NONNULL ((1, 2)));
286 _GL_CXXALIAS_SYS (stpncpy, char *,
287 (char *restrict __dst, char const *restrict __src,
290 _GL_CXXALIASWARN (stpncpy);
291 #elif defined GNULIB_POSIXCHECK
293 # if HAVE_RAW_DECL_STPNCPY
294 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
295 "use gnulib module stpncpy for portability");
299 #if defined GNULIB_POSIXCHECK
300 /* strchr() does not work with multibyte strings if the locale encoding is
301 GB18030 and the character to be searched is a digit. */
303 /* Assume strchr is always declared. */
304 _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
305 "in some multibyte locales - "
306 "use mbschr if you care about internationalization");
309 /* Find the first occurrence of C in S or the final NUL byte. */
310 #if @GNULIB_STRCHRNUL@
311 # if @REPLACE_STRCHRNUL@
312 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
313 # define strchrnul rpl_strchrnul
315 _GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in)
317 _GL_ARG_NONNULL ((1)));
318 _GL_CXXALIAS_RPL (strchrnul, char *,
319 (const char *str, int ch));
321 # if ! @HAVE_STRCHRNUL@
322 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
324 _GL_ARG_NONNULL ((1)));
326 /* On some systems, this function is defined as an overloaded function:
327 extern "C++" { const char * std::strchrnul (const char *, int); }
328 extern "C++" { char * std::strchrnul (char *, int); } */
329 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
330 char *, (char const *__s, int __c_in),
331 char const *, (char const *__s, int __c_in));
333 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
334 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
335 _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
336 _GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
338 _GL_CXXALIASWARN (strchrnul);
340 #elif defined GNULIB_POSIXCHECK
342 # if HAVE_RAW_DECL_STRCHRNUL
343 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
344 "use gnulib module strchrnul for portability");
348 /* Duplicate S, returning an identical malloc'd string. */
350 # if @REPLACE_STRDUP@
351 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
353 # define strdup rpl_strdup
355 _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
356 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
358 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
359 /* strdup exists as a function and as a macro. Get rid of the macro. */
362 # if !(@HAVE_DECL_STRDUP@ || defined strdup)
363 _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
365 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
367 _GL_CXXALIASWARN (strdup);
368 #elif defined GNULIB_POSIXCHECK
370 # if HAVE_RAW_DECL_STRDUP
371 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
372 "use gnulib module strdup for portability");
376 /* Append no more than N characters from SRC onto DEST. */
378 # if @REPLACE_STRNCAT@
379 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
381 # define strncat rpl_strncat
383 _GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n)
384 _GL_ARG_NONNULL ((1, 2)));
385 _GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n));
387 _GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n));
389 _GL_CXXALIASWARN (strncat);
390 #elif defined GNULIB_POSIXCHECK
392 # if HAVE_RAW_DECL_STRNCAT
393 _GL_WARN_ON_USE (strncat, "strncat is unportable - "
394 "use gnulib module strncat for portability");
398 /* Return a newly allocated copy of at most N bytes of STRING. */
400 # if @REPLACE_STRNDUP@
401 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
403 # define strndup rpl_strndup
405 _GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n)
406 _GL_ARG_NONNULL ((1)));
407 _GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n));
409 # if ! @HAVE_DECL_STRNDUP@
410 _GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n)
411 _GL_ARG_NONNULL ((1)));
413 _GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n));
415 _GL_CXXALIASWARN (strndup);
416 #elif defined GNULIB_POSIXCHECK
418 # if HAVE_RAW_DECL_STRNDUP
419 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
420 "use gnulib module strndup for portability");
424 /* Find the length (number of bytes) of STRING, but scan at most
425 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
428 # if @REPLACE_STRNLEN@
429 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
431 # define strnlen rpl_strnlen
433 _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
435 _GL_ARG_NONNULL ((1)));
436 _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
438 # if ! @HAVE_DECL_STRNLEN@
439 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
441 _GL_ARG_NONNULL ((1)));
443 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
445 _GL_CXXALIASWARN (strnlen);
446 #elif defined GNULIB_POSIXCHECK
448 # if HAVE_RAW_DECL_STRNLEN
449 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
450 "use gnulib module strnlen for portability");
454 #if defined GNULIB_POSIXCHECK
455 /* strcspn() assumes the second argument is a list of single-byte characters.
456 Even in this simple case, it does not work with multibyte strings if the
457 locale encoding is GB18030 and one of the characters to be searched is a
460 /* Assume strcspn is always declared. */
461 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
462 "in multibyte locales - "
463 "use mbscspn if you care about internationalization");
466 /* Find the first occurrence in S of any character in ACCEPT. */
468 # if ! @HAVE_STRPBRK@
469 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
471 _GL_ARG_NONNULL ((1, 2)));
473 /* On some systems, this function is defined as an overloaded function:
474 extern "C" { const char * strpbrk (const char *, const char *); }
475 extern "C++" { char * strpbrk (char *, const char *); } */
476 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
477 char *, (char const *__s, char const *__accept),
478 const char *, (char const *__s, char const *__accept));
479 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
480 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
481 _GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
482 _GL_CXXALIASWARN1 (strpbrk, char const *,
483 (char const *__s, char const *__accept));
485 _GL_CXXALIASWARN (strpbrk);
487 # if defined GNULIB_POSIXCHECK
488 /* strpbrk() assumes the second argument is a list of single-byte characters.
489 Even in this simple case, it does not work with multibyte strings if the
490 locale encoding is GB18030 and one of the characters to be searched is a
493 _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
494 "in multibyte locales - "
495 "use mbspbrk if you care about internationalization");
497 #elif defined GNULIB_POSIXCHECK
499 # if HAVE_RAW_DECL_STRPBRK
500 _GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
501 "use gnulib module strpbrk for portability");
505 #if defined GNULIB_POSIXCHECK
506 /* strspn() assumes the second argument is a list of single-byte characters.
507 Even in this simple case, it cannot work with multibyte strings. */
509 /* Assume strspn is always declared. */
510 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
511 "in multibyte locales - "
512 "use mbsspn if you care about internationalization");
515 #if defined GNULIB_POSIXCHECK
516 /* strrchr() does not work with multibyte strings if the locale encoding is
517 GB18030 and the character to be searched is a digit. */
519 /* Assume strrchr is always declared. */
520 _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
521 "in some multibyte locales - "
522 "use mbsrchr if you care about internationalization");
525 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
526 If one is found, overwrite it with a NUL, and advance *STRINGP
527 to point to the next char after it. Otherwise, set *STRINGP to NULL.
528 If *STRINGP was already NULL, nothing happens.
529 Return the old value of *STRINGP.
531 This is a variant of strtok() that is multithread-safe and supports
534 Caveat: It modifies the original string.
535 Caveat: These functions cannot be used on constant strings.
536 Caveat: The identity of the delimiting character is lost.
537 Caveat: It doesn't work with multibyte strings unless all of the delimiter
538 characters are ASCII characters < 0x30.
540 See also strtok_r(). */
543 _GL_FUNCDECL_SYS (strsep, char *,
544 (char **restrict __stringp, char const *restrict __delim)
545 _GL_ARG_NONNULL ((1, 2)));
547 _GL_CXXALIAS_SYS (strsep, char *,
548 (char **restrict __stringp, char const *restrict __delim));
549 _GL_CXXALIASWARN (strsep);
550 # if defined GNULIB_POSIXCHECK
552 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
553 "in multibyte locales - "
554 "use mbssep if you care about internationalization");
556 #elif defined GNULIB_POSIXCHECK
558 # if HAVE_RAW_DECL_STRSEP
559 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
560 "use gnulib module strsep for portability");
565 # if @REPLACE_STRSTR@
566 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
567 # define strstr rpl_strstr
569 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
571 _GL_ARG_NONNULL ((1, 2)));
572 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
574 /* On some systems, this function is defined as an overloaded function:
575 extern "C++" { const char * strstr (const char *, const char *); }
576 extern "C++" { char * strstr (char *, const char *); } */
577 _GL_CXXALIAS_SYS_CAST2 (strstr,
578 char *, (const char *haystack, const char *needle),
579 const char *, (const char *haystack, const char *needle));
581 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
582 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
583 _GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
584 _GL_CXXALIASWARN1 (strstr, const char *,
585 (const char *haystack, const char *needle));
587 _GL_CXXALIASWARN (strstr);
589 #elif defined GNULIB_POSIXCHECK
590 /* strstr() does not work with multibyte strings if the locale encoding is
591 different from UTF-8:
592 POSIX says that it operates on "strings", and "string" in POSIX is defined
593 as a sequence of bytes, not of characters. */
595 /* Assume strstr is always declared. */
596 _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
597 "work correctly on character strings in most "
598 "multibyte locales - "
599 "use mbsstr if you care about internationalization, "
600 "or use strstr if you care about speed");
603 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
605 #if @GNULIB_STRCASESTR@
606 # if @REPLACE_STRCASESTR@
607 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
608 # define strcasestr rpl_strcasestr
610 _GL_FUNCDECL_RPL (strcasestr, char *,
611 (const char *haystack, const char *needle)
613 _GL_ARG_NONNULL ((1, 2)));
614 _GL_CXXALIAS_RPL (strcasestr, char *,
615 (const char *haystack, const char *needle));
617 # if ! @HAVE_STRCASESTR@
618 _GL_FUNCDECL_SYS (strcasestr, char *,
619 (const char *haystack, const char *needle)
621 _GL_ARG_NONNULL ((1, 2)));
623 /* On some systems, this function is defined as an overloaded function:
624 extern "C++" { const char * strcasestr (const char *, const char *); }
625 extern "C++" { char * strcasestr (char *, const char *); } */
626 _GL_CXXALIAS_SYS_CAST2 (strcasestr,
627 char *, (const char *haystack, const char *needle),
628 const char *, (const char *haystack, const char *needle));
630 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
631 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
632 _GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
633 _GL_CXXALIASWARN1 (strcasestr, const char *,
634 (const char *haystack, const char *needle));
636 _GL_CXXALIASWARN (strcasestr);
638 #elif defined GNULIB_POSIXCHECK
639 /* strcasestr() does not work with multibyte strings:
640 It is a glibc extension, and glibc implements it only for unibyte
643 # if HAVE_RAW_DECL_STRCASESTR
644 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
645 "strings in multibyte locales - "
646 "use mbscasestr if you care about "
647 "internationalization, or use c-strcasestr if you want "
648 "a locale independent function");
652 /* Parse S into tokens separated by characters in DELIM.
653 If S is NULL, the saved pointer in SAVE_PTR is used as
654 the next starting point. For example:
655 char s[] = "-abc-=-def";
657 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
658 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
659 x = strtok_r(NULL, "=", &sp); // x = NULL
662 This is a variant of strtok() that is multithread-safe.
664 For the POSIX documentation for this function, see:
665 http://www.opengroup.org/susv3xsh/strtok.html
667 Caveat: It modifies the original string.
668 Caveat: These functions cannot be used on constant strings.
669 Caveat: The identity of the delimiting character is lost.
670 Caveat: It doesn't work with multibyte strings unless all of the delimiter
671 characters are ASCII characters < 0x30.
673 See also strsep(). */
674 #if @GNULIB_STRTOK_R@
675 # if @REPLACE_STRTOK_R@
676 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
678 # define strtok_r rpl_strtok_r
680 _GL_FUNCDECL_RPL (strtok_r, char *,
681 (char *restrict s, char const *restrict delim,
682 char **restrict save_ptr)
683 _GL_ARG_NONNULL ((2, 3)));
684 _GL_CXXALIAS_RPL (strtok_r, char *,
685 (char *restrict s, char const *restrict delim,
686 char **restrict save_ptr));
688 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
691 # if ! @HAVE_DECL_STRTOK_R@
692 _GL_FUNCDECL_SYS (strtok_r, char *,
693 (char *restrict s, char const *restrict delim,
694 char **restrict save_ptr)
695 _GL_ARG_NONNULL ((2, 3)));
697 _GL_CXXALIAS_SYS (strtok_r, char *,
698 (char *restrict s, char const *restrict delim,
699 char **restrict save_ptr));
701 _GL_CXXALIASWARN (strtok_r);
702 # if defined GNULIB_POSIXCHECK
703 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
704 "strings in multibyte locales - "
705 "use mbstok_r if you care about internationalization");
707 #elif defined GNULIB_POSIXCHECK
709 # if HAVE_RAW_DECL_STRTOK_R
710 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
711 "use gnulib module strtok_r for portability");
716 /* The following functions are not specified by POSIX. They are gnulib
720 /* Return the number of multibyte characters in the character string STRING.
721 This considers multibyte characters, unlike strlen, which counts bytes. */
722 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
725 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
726 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
727 # define mbslen rpl_mbslen
729 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string)
731 _GL_ARG_NONNULL ((1)));
732 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
734 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string)
736 _GL_ARG_NONNULL ((1)));
737 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
739 _GL_CXXALIASWARN (mbslen);
743 /* Return the number of multibyte characters in the character string starting
744 at STRING and ending at STRING + LEN. */
745 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
747 _GL_ARG_NONNULL ((1));
751 /* Locate the first single-byte character C in the character string STRING,
752 and return a pointer to it. Return NULL if C is not found in STRING.
753 Unlike strchr(), this function works correctly in multibyte locales with
754 encodings such as GB18030. */
756 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
757 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
759 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
761 _GL_ARG_NONNULL ((1)));
762 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
764 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
766 _GL_ARG_NONNULL ((1)));
767 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
769 _GL_CXXALIASWARN (mbschr);
773 /* Locate the last single-byte character C in the character string STRING,
774 and return a pointer to it. Return NULL if C is not found in STRING.
775 Unlike strrchr(), this function works correctly in multibyte locales with
776 encodings such as GB18030. */
777 # if defined __hpux || defined __INTERIX
778 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
779 # define mbsrchr rpl_mbsrchr /* avoid collision with system function */
781 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
783 _GL_ARG_NONNULL ((1)));
784 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
786 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
788 _GL_ARG_NONNULL ((1)));
789 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
791 _GL_CXXALIASWARN (mbsrchr);
795 /* Find the first occurrence of the character string NEEDLE in the character
796 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
797 Unlike strstr(), this function works correctly in multibyte locales with
798 encodings different from UTF-8. */
799 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
801 _GL_ARG_NONNULL ((1, 2));
804 #if @GNULIB_MBSCASECMP@
805 /* Compare the character strings S1 and S2, ignoring case, returning less than,
806 equal to or greater than zero if S1 is lexicographically less than, equal to
808 Note: This function may, in multibyte locales, return 0 for strings of
810 Unlike strcasecmp(), this function works correctly in multibyte locales. */
811 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
813 _GL_ARG_NONNULL ((1, 2));
816 #if @GNULIB_MBSNCASECMP@
817 /* Compare the initial segment of the character string S1 consisting of at most
818 N characters with the initial segment of the character string S2 consisting
819 of at most N characters, ignoring case, returning less than, equal to or
820 greater than zero if the initial segment of S1 is lexicographically less
821 than, equal to or greater than the initial segment of S2.
822 Note: This function may, in multibyte locales, return 0 for initial segments
823 of different lengths!
824 Unlike strncasecmp(), this function works correctly in multibyte locales.
825 But beware that N is not a byte count but a character count! */
826 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
828 _GL_ARG_NONNULL ((1, 2));
831 #if @GNULIB_MBSPCASECMP@
832 /* Compare the initial segment of the character string STRING consisting of
833 at most mbslen (PREFIX) characters with the character string PREFIX,
834 ignoring case. If the two match, return a pointer to the first byte
835 after this prefix in STRING. Otherwise, return NULL.
836 Note: This function may, in multibyte locales, return non-NULL if STRING
837 is of smaller length than PREFIX!
838 Unlike strncasecmp(), this function works correctly in multibyte
840 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
842 _GL_ARG_NONNULL ((1, 2));
845 #if @GNULIB_MBSCASESTR@
846 /* Find the first occurrence of the character string NEEDLE in the character
847 string HAYSTACK, using case-insensitive comparison.
848 Note: This function may, in multibyte locales, return success even if
849 strlen (haystack) < strlen (needle) !
850 Unlike strcasestr(), this function works correctly in multibyte locales. */
851 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
853 _GL_ARG_NONNULL ((1, 2));
857 /* Find the first occurrence in the character string STRING of any character
858 in the character string ACCEPT. Return the number of bytes from the
859 beginning of the string to this occurrence, or to the end of the string
861 Unlike strcspn(), this function works correctly in multibyte locales. */
862 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
864 _GL_ARG_NONNULL ((1, 2));
868 /* Find the first occurrence in the character string STRING of any character
869 in the character string ACCEPT. Return the pointer to it, or NULL if none
871 Unlike strpbrk(), this function works correctly in multibyte locales. */
873 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
874 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
876 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
878 _GL_ARG_NONNULL ((1, 2)));
879 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
881 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
883 _GL_ARG_NONNULL ((1, 2)));
884 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
886 _GL_CXXALIASWARN (mbspbrk);
890 /* Find the first occurrence in the character string STRING of any character
891 not in the character string REJECT. Return the number of bytes from the
892 beginning of the string to this occurrence, or to the end of the string
894 Unlike strspn(), this function works correctly in multibyte locales. */
895 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
897 _GL_ARG_NONNULL ((1, 2));
901 /* Search the next delimiter (multibyte character listed in the character
902 string DELIM) starting at the character string *STRINGP.
903 If one is found, overwrite it with a NUL, and advance *STRINGP to point
904 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
905 If *STRINGP was already NULL, nothing happens.
906 Return the old value of *STRINGP.
908 This is a variant of mbstok_r() that supports empty fields.
910 Caveat: It modifies the original string.
911 Caveat: These functions cannot be used on constant strings.
912 Caveat: The identity of the delimiting character is lost.
914 See also mbstok_r(). */
915 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
916 _GL_ARG_NONNULL ((1, 2));
919 #if @GNULIB_MBSTOK_R@
920 /* Parse the character string STRING into tokens separated by characters in
921 the character string DELIM.
922 If STRING is NULL, the saved pointer in SAVE_PTR is used as
923 the next starting point. For example:
924 char s[] = "-abc-=-def";
926 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
927 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
928 x = mbstok_r(NULL, "=", &sp); // x = NULL
931 Caveat: It modifies the original string.
932 Caveat: These functions cannot be used on constant strings.
933 Caveat: The identity of the delimiting character is lost.
935 See also mbssep(). */
936 _GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr)
937 _GL_ARG_NONNULL ((2, 3));
940 /* Map any int, typically from errno, into an error message. */
941 #if @GNULIB_STRERROR@
942 # if @REPLACE_STRERROR@
943 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
945 # define strerror rpl_strerror
947 _GL_FUNCDECL_RPL (strerror, char *, (int));
948 _GL_CXXALIAS_RPL (strerror, char *, (int));
950 _GL_CXXALIAS_SYS (strerror, char *, (int));
952 _GL_CXXALIASWARN (strerror);
953 #elif defined GNULIB_POSIXCHECK
955 /* Assume strerror is always declared. */
956 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
957 "use gnulib module strerror to guarantee non-NULL result");
960 /* Map any int, typically from errno, into an error message. Multithread-safe.
961 Uses the POSIX declaration, not the glibc declaration. */
962 #if @GNULIB_STRERROR_R@
963 # if @REPLACE_STRERROR_R@
964 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
966 # define strerror_r rpl_strerror_r
968 _GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)
969 _GL_ARG_NONNULL ((2)));
970 _GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
972 # if !@HAVE_DECL_STRERROR_R@
973 _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)
974 _GL_ARG_NONNULL ((2)));
976 _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
978 # if @HAVE_DECL_STRERROR_R@
979 _GL_CXXALIASWARN (strerror_r);
981 #elif defined GNULIB_POSIXCHECK
983 # if HAVE_RAW_DECL_STRERROR_R
984 _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
985 "use gnulib module strerror_r-posix for portability");
989 #if @GNULIB_STRSIGNAL@
990 # if @REPLACE_STRSIGNAL@
991 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
992 # define strsignal rpl_strsignal
994 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
995 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
997 # if ! @HAVE_DECL_STRSIGNAL@
998 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
1000 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
1002 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
1004 _GL_CXXALIASWARN (strsignal);
1005 #elif defined GNULIB_POSIXCHECK
1007 # if HAVE_RAW_DECL_STRSIGNAL
1008 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
1009 "use gnulib module strsignal for portability");
1013 #if @GNULIB_STRVERSCMP@
1014 # if !@HAVE_STRVERSCMP@
1015 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
1017 _GL_ARG_NONNULL ((1, 2)));
1019 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
1020 _GL_CXXALIASWARN (strverscmp);
1021 #elif defined GNULIB_POSIXCHECK
1023 # if HAVE_RAW_DECL_STRVERSCMP
1024 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1025 "use gnulib module strverscmp for portability");
1030 #endif /* _@GUARD_PREFIX@_STRING_H */
1031 #endif /* _@GUARD_PREFIX@_STRING_H */