1 /* A GNU-like <string.h>.
3 Copyright (C) 1995-1996, 2001-2011 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. */
19 #ifndef _@GUARD_PREFIX@_STRING_H
22 @PRAGMA_SYSTEM_HEADER@
26 /* The include_next requires a split double-inclusion guard. */
27 #@INCLUDE_NEXT@ @NEXT_STRING_H@
29 #ifndef _@GUARD_PREFIX@_STRING_H
30 #define _@GUARD_PREFIX@_STRING_H
32 /* NetBSD 5.0 mis-defines NULL. */
35 /* MirBSD defines mbslen as a macro. */
36 #if @GNULIB_MBSLEN@ && defined __MirBSD__
40 /* The __attribute__ feature is available in gcc versions 2.5 and later.
41 The attribute __pure__ was added in gcc 2.96. */
42 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
43 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
45 # define _GL_ATTRIBUTE_PURE /* empty */
48 /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
49 /* But in any case avoid namespace pollution on glibc systems. */
50 #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
51 && ! defined __GLIBC__
55 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
57 /* The definition of _GL_ARG_NONNULL is copied here. */
59 /* The definition of _GL_WARN_ON_USE is copied here. */
62 /* Return the first instance of C within N bytes of S, or NULL. */
65 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
66 # define memchr rpl_memchr
68 _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
70 _GL_ARG_NONNULL ((1)));
71 _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
74 _GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n)
76 _GL_ARG_NONNULL ((1)));
78 /* On some systems, this function is defined as an overloaded function:
79 extern "C" { const void * std::memchr (const void *, int, size_t); }
80 extern "C++" { void * std::memchr (void *, int, size_t); } */
81 _GL_CXXALIAS_SYS_CAST2 (memchr,
82 void *, (void const *__s, int __c, size_t __n),
83 void const *, (void const *__s, int __c, size_t __n));
85 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
86 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
87 _GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
88 _GL_CXXALIASWARN1 (memchr, void const *,
89 (void const *__s, int __c, size_t __n));
91 _GL_CXXALIASWARN (memchr);
93 #elif defined GNULIB_POSIXCHECK
95 /* Assume memchr is always declared. */
96 _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
97 "use gnulib module memchr for portability" );
100 /* Return the first occurrence of NEEDLE in HAYSTACK. */
102 # if @REPLACE_MEMMEM@
103 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
104 # define memmem rpl_memmem
106 _GL_FUNCDECL_RPL (memmem, void *,
107 (void const *__haystack, size_t __haystack_len,
108 void const *__needle, size_t __needle_len)
110 _GL_ARG_NONNULL ((1, 3)));
111 _GL_CXXALIAS_RPL (memmem, void *,
112 (void const *__haystack, size_t __haystack_len,
113 void const *__needle, size_t __needle_len));
115 # if ! @HAVE_DECL_MEMMEM@
116 _GL_FUNCDECL_SYS (memmem, void *,
117 (void const *__haystack, size_t __haystack_len,
118 void const *__needle, size_t __needle_len)
120 _GL_ARG_NONNULL ((1, 3)));
122 _GL_CXXALIAS_SYS (memmem, void *,
123 (void const *__haystack, size_t __haystack_len,
124 void const *__needle, size_t __needle_len));
126 _GL_CXXALIASWARN (memmem);
127 #elif defined GNULIB_POSIXCHECK
129 # if HAVE_RAW_DECL_MEMMEM
130 _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
131 "use gnulib module memmem-simple for portability, "
132 "and module memmem for speed" );
136 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
137 last written byte. */
139 # if ! @HAVE_MEMPCPY@
140 _GL_FUNCDECL_SYS (mempcpy, void *,
141 (void *restrict __dest, void const *restrict __src,
143 _GL_ARG_NONNULL ((1, 2)));
145 _GL_CXXALIAS_SYS (mempcpy, void *,
146 (void *restrict __dest, void const *restrict __src,
148 _GL_CXXALIASWARN (mempcpy);
149 #elif defined GNULIB_POSIXCHECK
151 # if HAVE_RAW_DECL_MEMPCPY
152 _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
153 "use gnulib module mempcpy for portability");
157 /* Search backwards through a block for a byte (specified as an int). */
159 # if ! @HAVE_DECL_MEMRCHR@
160 _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
162 _GL_ARG_NONNULL ((1)));
164 /* On some systems, this function is defined as an overloaded function:
165 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
166 extern "C++" { void * std::memrchr (void *, int, size_t); } */
167 _GL_CXXALIAS_SYS_CAST2 (memrchr,
168 void *, (void const *, int, size_t),
169 void const *, (void const *, int, size_t));
170 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
171 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
172 _GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
173 _GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
175 _GL_CXXALIASWARN (memrchr);
177 #elif defined GNULIB_POSIXCHECK
179 # if HAVE_RAW_DECL_MEMRCHR
180 _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
181 "use gnulib module memrchr for portability");
185 /* Find the first occurrence of C in S. More efficient than
186 memchr(S,C,N), at the expense of undefined behavior if C does not
187 occur within N bytes. */
188 #if @GNULIB_RAWMEMCHR@
189 # if ! @HAVE_RAWMEMCHR@
190 _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
192 _GL_ARG_NONNULL ((1)));
194 /* On some systems, this function is defined as an overloaded function:
195 extern "C++" { const void * std::rawmemchr (const void *, int); }
196 extern "C++" { void * std::rawmemchr (void *, int); } */
197 _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
198 void *, (void const *__s, int __c_in),
199 void const *, (void const *__s, int __c_in));
200 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
201 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
202 _GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
203 _GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
205 _GL_CXXALIASWARN (rawmemchr);
207 #elif defined GNULIB_POSIXCHECK
209 # if HAVE_RAW_DECL_RAWMEMCHR
210 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
211 "use gnulib module rawmemchr for portability");
215 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
218 _GL_FUNCDECL_SYS (stpcpy, char *,
219 (char *restrict __dst, char const *restrict __src)
220 _GL_ARG_NONNULL ((1, 2)));
222 _GL_CXXALIAS_SYS (stpcpy, char *,
223 (char *restrict __dst, char const *restrict __src));
224 _GL_CXXALIASWARN (stpcpy);
225 #elif defined GNULIB_POSIXCHECK
227 # if HAVE_RAW_DECL_STPCPY
228 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
229 "use gnulib module stpcpy for portability");
233 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
234 last non-NUL byte written into DST. */
236 # if @REPLACE_STPNCPY@
237 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
239 # define stpncpy rpl_stpncpy
241 _GL_FUNCDECL_RPL (stpncpy, char *,
242 (char *restrict __dst, char const *restrict __src,
244 _GL_ARG_NONNULL ((1, 2)));
245 _GL_CXXALIAS_RPL (stpncpy, char *,
246 (char *restrict __dst, char const *restrict __src,
249 # if ! @HAVE_STPNCPY@
250 _GL_FUNCDECL_SYS (stpncpy, char *,
251 (char *restrict __dst, char const *restrict __src,
253 _GL_ARG_NONNULL ((1, 2)));
255 _GL_CXXALIAS_SYS (stpncpy, char *,
256 (char *restrict __dst, char const *restrict __src,
259 _GL_CXXALIASWARN (stpncpy);
260 #elif defined GNULIB_POSIXCHECK
262 # if HAVE_RAW_DECL_STPNCPY
263 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
264 "use gnulib module stpncpy for portability");
268 #if defined GNULIB_POSIXCHECK
269 /* strchr() does not work with multibyte strings if the locale encoding is
270 GB18030 and the character to be searched is a digit. */
272 /* Assume strchr is always declared. */
273 _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
274 "in some multibyte locales - "
275 "use mbschr if you care about internationalization");
278 /* Find the first occurrence of C in S or the final NUL byte. */
279 #if @GNULIB_STRCHRNUL@
280 # if @REPLACE_STRCHRNUL@
281 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
282 # define strchrnul rpl_strchrnul
284 _GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in)
286 _GL_ARG_NONNULL ((1)));
287 _GL_CXXALIAS_RPL (strchrnul, char *,
288 (const char *str, int ch));
290 # if ! @HAVE_STRCHRNUL@
291 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
293 _GL_ARG_NONNULL ((1)));
295 /* On some systems, this function is defined as an overloaded function:
296 extern "C++" { const char * std::strchrnul (const char *, int); }
297 extern "C++" { char * std::strchrnul (char *, int); } */
298 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
299 char *, (char const *__s, int __c_in),
300 char const *, (char const *__s, int __c_in));
302 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
303 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
304 _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
305 _GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
307 _GL_CXXALIASWARN (strchrnul);
309 #elif defined GNULIB_POSIXCHECK
311 # if HAVE_RAW_DECL_STRCHRNUL
312 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
313 "use gnulib module strchrnul for portability");
317 /* Duplicate S, returning an identical malloc'd string. */
319 # if @REPLACE_STRDUP@
320 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
322 # define strdup rpl_strdup
324 _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
325 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
327 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
328 /* strdup exists as a function and as a macro. Get rid of the macro. */
331 # if !(@HAVE_DECL_STRDUP@ || defined strdup)
332 _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
334 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
336 _GL_CXXALIASWARN (strdup);
337 #elif defined GNULIB_POSIXCHECK
339 # if HAVE_RAW_DECL_STRDUP
340 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
341 "use gnulib module strdup for portability");
345 /* Append no more than N characters from SRC onto DEST. */
347 # if @REPLACE_STRNCAT@
348 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
350 # define strncat rpl_strncat
352 _GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n)
353 _GL_ARG_NONNULL ((1, 2)));
354 _GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n));
356 _GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n));
358 _GL_CXXALIASWARN (strncat);
359 #elif defined GNULIB_POSIXCHECK
361 # if HAVE_RAW_DECL_STRNCAT
362 _GL_WARN_ON_USE (strncat, "strncat is unportable - "
363 "use gnulib module strncat for portability");
367 /* Return a newly allocated copy of at most N bytes of STRING. */
369 # if @REPLACE_STRNDUP@
370 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
372 # define strndup rpl_strndup
374 _GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n)
375 _GL_ARG_NONNULL ((1)));
376 _GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n));
378 # if ! @HAVE_DECL_STRNDUP@
379 _GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n)
380 _GL_ARG_NONNULL ((1)));
382 _GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n));
384 _GL_CXXALIASWARN (strndup);
385 #elif defined GNULIB_POSIXCHECK
387 # if HAVE_RAW_DECL_STRNDUP
388 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
389 "use gnulib module strndup for portability");
393 /* Find the length (number of bytes) of STRING, but scan at most
394 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
397 # if @REPLACE_STRNLEN@
398 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
400 # define strnlen rpl_strnlen
402 _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
404 _GL_ARG_NONNULL ((1)));
405 _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
407 # if ! @HAVE_DECL_STRNLEN@
408 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
410 _GL_ARG_NONNULL ((1)));
412 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
414 _GL_CXXALIASWARN (strnlen);
415 #elif defined GNULIB_POSIXCHECK
417 # if HAVE_RAW_DECL_STRNLEN
418 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
419 "use gnulib module strnlen for portability");
423 #if defined GNULIB_POSIXCHECK
424 /* strcspn() assumes the second argument is a list of single-byte characters.
425 Even in this simple case, it does not work with multibyte strings if the
426 locale encoding is GB18030 and one of the characters to be searched is a
429 /* Assume strcspn is always declared. */
430 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
431 "in multibyte locales - "
432 "use mbscspn if you care about internationalization");
435 /* Find the first occurrence in S of any character in ACCEPT. */
437 # if ! @HAVE_STRPBRK@
438 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
440 _GL_ARG_NONNULL ((1, 2)));
442 /* On some systems, this function is defined as an overloaded function:
443 extern "C" { const char * strpbrk (const char *, const char *); }
444 extern "C++" { char * strpbrk (char *, const char *); } */
445 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
446 char *, (char const *__s, char const *__accept),
447 const char *, (char const *__s, char const *__accept));
448 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
449 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
450 _GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
451 _GL_CXXALIASWARN1 (strpbrk, char const *,
452 (char const *__s, char const *__accept));
454 _GL_CXXALIASWARN (strpbrk);
456 # if defined GNULIB_POSIXCHECK
457 /* strpbrk() assumes the second argument is a list of single-byte characters.
458 Even in this simple case, it does not work with multibyte strings if the
459 locale encoding is GB18030 and one of the characters to be searched is a
462 _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
463 "in multibyte locales - "
464 "use mbspbrk if you care about internationalization");
466 #elif defined GNULIB_POSIXCHECK
468 # if HAVE_RAW_DECL_STRPBRK
469 _GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
470 "use gnulib module strpbrk for portability");
474 #if defined GNULIB_POSIXCHECK
475 /* strspn() assumes the second argument is a list of single-byte characters.
476 Even in this simple case, it cannot work with multibyte strings. */
478 /* Assume strspn is always declared. */
479 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
480 "in multibyte locales - "
481 "use mbsspn if you care about internationalization");
484 #if defined GNULIB_POSIXCHECK
485 /* strrchr() does not work with multibyte strings if the locale encoding is
486 GB18030 and the character to be searched is a digit. */
488 /* Assume strrchr is always declared. */
489 _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
490 "in some multibyte locales - "
491 "use mbsrchr if you care about internationalization");
494 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
495 If one is found, overwrite it with a NUL, and advance *STRINGP
496 to point to the next char after it. Otherwise, set *STRINGP to NULL.
497 If *STRINGP was already NULL, nothing happens.
498 Return the old value of *STRINGP.
500 This is a variant of strtok() that is multithread-safe and supports
503 Caveat: It modifies the original string.
504 Caveat: These functions cannot be used on constant strings.
505 Caveat: The identity of the delimiting character is lost.
506 Caveat: It doesn't work with multibyte strings unless all of the delimiter
507 characters are ASCII characters < 0x30.
509 See also strtok_r(). */
512 _GL_FUNCDECL_SYS (strsep, char *,
513 (char **restrict __stringp, char const *restrict __delim)
514 _GL_ARG_NONNULL ((1, 2)));
516 _GL_CXXALIAS_SYS (strsep, char *,
517 (char **restrict __stringp, char const *restrict __delim));
518 _GL_CXXALIASWARN (strsep);
519 # if defined GNULIB_POSIXCHECK
521 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
522 "in multibyte locales - "
523 "use mbssep if you care about internationalization");
525 #elif defined GNULIB_POSIXCHECK
527 # if HAVE_RAW_DECL_STRSEP
528 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
529 "use gnulib module strsep for portability");
534 # if @REPLACE_STRSTR@
535 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
536 # define strstr rpl_strstr
538 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
540 _GL_ARG_NONNULL ((1, 2)));
541 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
543 /* On some systems, this function is defined as an overloaded function:
544 extern "C++" { const char * strstr (const char *, const char *); }
545 extern "C++" { char * strstr (char *, const char *); } */
546 _GL_CXXALIAS_SYS_CAST2 (strstr,
547 char *, (const char *haystack, const char *needle),
548 const char *, (const char *haystack, const char *needle));
550 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
551 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
552 _GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
553 _GL_CXXALIASWARN1 (strstr, const char *,
554 (const char *haystack, const char *needle));
556 _GL_CXXALIASWARN (strstr);
558 #elif defined GNULIB_POSIXCHECK
559 /* strstr() does not work with multibyte strings if the locale encoding is
560 different from UTF-8:
561 POSIX says that it operates on "strings", and "string" in POSIX is defined
562 as a sequence of bytes, not of characters. */
564 /* Assume strstr is always declared. */
565 _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
566 "work correctly on character strings in most "
567 "multibyte locales - "
568 "use mbsstr if you care about internationalization, "
569 "or use strstr if you care about speed");
572 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
574 #if @GNULIB_STRCASESTR@
575 # if @REPLACE_STRCASESTR@
576 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
577 # define strcasestr rpl_strcasestr
579 _GL_FUNCDECL_RPL (strcasestr, char *,
580 (const char *haystack, const char *needle)
582 _GL_ARG_NONNULL ((1, 2)));
583 _GL_CXXALIAS_RPL (strcasestr, char *,
584 (const char *haystack, const char *needle));
586 # if ! @HAVE_STRCASESTR@
587 _GL_FUNCDECL_SYS (strcasestr, char *,
588 (const char *haystack, const char *needle)
590 _GL_ARG_NONNULL ((1, 2)));
592 /* On some systems, this function is defined as an overloaded function:
593 extern "C++" { const char * strcasestr (const char *, const char *); }
594 extern "C++" { char * strcasestr (char *, const char *); } */
595 _GL_CXXALIAS_SYS_CAST2 (strcasestr,
596 char *, (const char *haystack, const char *needle),
597 const char *, (const char *haystack, const char *needle));
599 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
600 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
601 _GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
602 _GL_CXXALIASWARN1 (strcasestr, const char *,
603 (const char *haystack, const char *needle));
605 _GL_CXXALIASWARN (strcasestr);
607 #elif defined GNULIB_POSIXCHECK
608 /* strcasestr() does not work with multibyte strings:
609 It is a glibc extension, and glibc implements it only for unibyte
612 # if HAVE_RAW_DECL_STRCASESTR
613 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
614 "strings in multibyte locales - "
615 "use mbscasestr if you care about "
616 "internationalization, or use c-strcasestr if you want "
617 "a locale independent function");
621 /* Parse S into tokens separated by characters in DELIM.
622 If S is NULL, the saved pointer in SAVE_PTR is used as
623 the next starting point. For example:
624 char s[] = "-abc-=-def";
626 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
627 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
628 x = strtok_r(NULL, "=", &sp); // x = NULL
631 This is a variant of strtok() that is multithread-safe.
633 For the POSIX documentation for this function, see:
634 http://www.opengroup.org/susv3xsh/strtok.html
636 Caveat: It modifies the original string.
637 Caveat: These functions cannot be used on constant strings.
638 Caveat: The identity of the delimiting character is lost.
639 Caveat: It doesn't work with multibyte strings unless all of the delimiter
640 characters are ASCII characters < 0x30.
642 See also strsep(). */
643 #if @GNULIB_STRTOK_R@
644 # if @REPLACE_STRTOK_R@
645 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
647 # define strtok_r rpl_strtok_r
649 _GL_FUNCDECL_RPL (strtok_r, char *,
650 (char *restrict s, char const *restrict delim,
651 char **restrict save_ptr)
652 _GL_ARG_NONNULL ((2, 3)));
653 _GL_CXXALIAS_RPL (strtok_r, char *,
654 (char *restrict s, char const *restrict delim,
655 char **restrict save_ptr));
657 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
660 # if ! @HAVE_DECL_STRTOK_R@
661 _GL_FUNCDECL_SYS (strtok_r, char *,
662 (char *restrict s, char const *restrict delim,
663 char **restrict save_ptr)
664 _GL_ARG_NONNULL ((2, 3)));
666 _GL_CXXALIAS_SYS (strtok_r, char *,
667 (char *restrict s, char const *restrict delim,
668 char **restrict save_ptr));
670 _GL_CXXALIASWARN (strtok_r);
671 # if defined GNULIB_POSIXCHECK
672 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
673 "strings in multibyte locales - "
674 "use mbstok_r if you care about internationalization");
676 #elif defined GNULIB_POSIXCHECK
678 # if HAVE_RAW_DECL_STRTOK_R
679 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
680 "use gnulib module strtok_r for portability");
685 /* The following functions are not specified by POSIX. They are gnulib
689 /* Return the number of multibyte characters in the character string STRING.
690 This considers multibyte characters, unlike strlen, which counts bytes. */
691 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
694 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
695 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
696 # define mbslen rpl_mbslen
698 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
699 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
701 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
702 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
704 _GL_CXXALIASWARN (mbslen);
708 /* Return the number of multibyte characters in the character string starting
709 at STRING and ending at STRING + LEN. */
710 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
711 _GL_ARG_NONNULL ((1));
715 /* Locate the first single-byte character C in the character string STRING,
716 and return a pointer to it. Return NULL if C is not found in STRING.
717 Unlike strchr(), this function works correctly in multibyte locales with
718 encodings such as GB18030. */
720 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
721 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
723 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
724 _GL_ARG_NONNULL ((1)));
725 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
727 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
728 _GL_ARG_NONNULL ((1)));
729 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
731 _GL_CXXALIASWARN (mbschr);
735 /* Locate the last single-byte character C in the character string STRING,
736 and return a pointer to it. Return NULL if C is not found in STRING.
737 Unlike strrchr(), this function works correctly in multibyte locales with
738 encodings such as GB18030. */
739 # if defined __hpux || defined __INTERIX
740 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
741 # define mbsrchr rpl_mbsrchr /* avoid collision with system function */
743 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
744 _GL_ARG_NONNULL ((1)));
745 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
747 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
748 _GL_ARG_NONNULL ((1)));
749 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
751 _GL_CXXALIASWARN (mbsrchr);
755 /* Find the first occurrence of the character string NEEDLE in the character
756 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
757 Unlike strstr(), this function works correctly in multibyte locales with
758 encodings different from UTF-8. */
759 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
760 _GL_ARG_NONNULL ((1, 2));
763 #if @GNULIB_MBSCASECMP@
764 /* Compare the character strings S1 and S2, ignoring case, returning less than,
765 equal to or greater than zero if S1 is lexicographically less than, equal to
767 Note: This function may, in multibyte locales, return 0 for strings of
769 Unlike strcasecmp(), this function works correctly in multibyte locales. */
770 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
771 _GL_ARG_NONNULL ((1, 2));
774 #if @GNULIB_MBSNCASECMP@
775 /* Compare the initial segment of the character string S1 consisting of at most
776 N characters with the initial segment of the character string S2 consisting
777 of at most N characters, ignoring case, returning less than, equal to or
778 greater than zero if the initial segment of S1 is lexicographically less
779 than, equal to or greater than the initial segment of S2.
780 Note: This function may, in multibyte locales, return 0 for initial segments
781 of different lengths!
782 Unlike strncasecmp(), this function works correctly in multibyte locales.
783 But beware that N is not a byte count but a character count! */
784 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
785 _GL_ARG_NONNULL ((1, 2));
788 #if @GNULIB_MBSPCASECMP@
789 /* Compare the initial segment of the character string STRING consisting of
790 at most mbslen (PREFIX) characters with the character string PREFIX,
791 ignoring case. If the two match, return a pointer to the first byte
792 after this prefix in STRING. Otherwise, return NULL.
793 Note: This function may, in multibyte locales, return non-NULL if STRING
794 is of smaller length than PREFIX!
795 Unlike strncasecmp(), this function works correctly in multibyte
797 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
798 _GL_ARG_NONNULL ((1, 2));
801 #if @GNULIB_MBSCASESTR@
802 /* Find the first occurrence of the character string NEEDLE in the character
803 string HAYSTACK, using case-insensitive comparison.
804 Note: This function may, in multibyte locales, return success even if
805 strlen (haystack) < strlen (needle) !
806 Unlike strcasestr(), this function works correctly in multibyte locales. */
807 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
808 _GL_ARG_NONNULL ((1, 2));
812 /* Find the first occurrence in the character string STRING of any character
813 in the character string ACCEPT. Return the number of bytes from the
814 beginning of the string to this occurrence, or to the end of the string
816 Unlike strcspn(), this function works correctly in multibyte locales. */
817 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
818 _GL_ARG_NONNULL ((1, 2));
822 /* Find the first occurrence in the character string STRING of any character
823 in the character string ACCEPT. Return the pointer to it, or NULL if none
825 Unlike strpbrk(), this function works correctly in multibyte locales. */
827 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
828 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
830 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
831 _GL_ARG_NONNULL ((1, 2)));
832 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
834 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
835 _GL_ARG_NONNULL ((1, 2)));
836 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
838 _GL_CXXALIASWARN (mbspbrk);
842 /* Find the first occurrence in the character string STRING of any character
843 not in the character string REJECT. Return the number of bytes from the
844 beginning of the string to this occurrence, or to the end of the string
846 Unlike strspn(), this function works correctly in multibyte locales. */
847 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
848 _GL_ARG_NONNULL ((1, 2));
852 /* Search the next delimiter (multibyte character listed in the character
853 string DELIM) starting at the character string *STRINGP.
854 If one is found, overwrite it with a NUL, and advance *STRINGP to point
855 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
856 If *STRINGP was already NULL, nothing happens.
857 Return the old value of *STRINGP.
859 This is a variant of mbstok_r() that supports empty fields.
861 Caveat: It modifies the original string.
862 Caveat: These functions cannot be used on constant strings.
863 Caveat: The identity of the delimiting character is lost.
865 See also mbstok_r(). */
866 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
867 _GL_ARG_NONNULL ((1, 2));
870 #if @GNULIB_MBSTOK_R@
871 /* Parse the character string STRING into tokens separated by characters in
872 the character string DELIM.
873 If STRING is NULL, the saved pointer in SAVE_PTR is used as
874 the next starting point. For example:
875 char s[] = "-abc-=-def";
877 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
878 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
879 x = mbstok_r(NULL, "=", &sp); // x = NULL
882 Caveat: It modifies the original string.
883 Caveat: These functions cannot be used on constant strings.
884 Caveat: The identity of the delimiting character is lost.
886 See also mbssep(). */
887 _GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr)
888 _GL_ARG_NONNULL ((2, 3));
891 /* Map any int, typically from errno, into an error message. */
892 #if @GNULIB_STRERROR@
893 # if @REPLACE_STRERROR@
894 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
896 # define strerror rpl_strerror
898 _GL_FUNCDECL_RPL (strerror, char *, (int));
899 _GL_CXXALIAS_RPL (strerror, char *, (int));
901 _GL_CXXALIAS_SYS (strerror, char *, (int));
903 _GL_CXXALIASWARN (strerror);
904 #elif defined GNULIB_POSIXCHECK
906 /* Assume strerror is always declared. */
907 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
908 "use gnulib module strerror to guarantee non-NULL result");
911 /* Map any int, typically from errno, into an error message. Multithread-safe.
912 Uses the POSIX declaration, not the glibc declaration. */
913 #if @GNULIB_STRERROR_R@
914 # if @REPLACE_STRERROR_R@
915 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
917 # define strerror_r rpl_strerror_r
919 _GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)
920 _GL_ARG_NONNULL ((2)));
921 _GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
923 # if !@HAVE_DECL_STRERROR_R@
924 _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)
925 _GL_ARG_NONNULL ((2)));
927 _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
929 # if @HAVE_DECL_STRERROR_R@
930 _GL_CXXALIASWARN (strerror_r);
932 #elif defined GNULIB_POSIXCHECK
934 # if HAVE_RAW_DECL_STRERROR_R
935 _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
936 "use gnulib module strerror_r-posix for portability");
940 #if @GNULIB_STRSIGNAL@
941 # if @REPLACE_STRSIGNAL@
942 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
943 # define strsignal rpl_strsignal
945 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
946 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
948 # if ! @HAVE_DECL_STRSIGNAL@
949 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
951 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
953 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
955 _GL_CXXALIASWARN (strsignal);
956 #elif defined GNULIB_POSIXCHECK
958 # if HAVE_RAW_DECL_STRSIGNAL
959 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
960 "use gnulib module strsignal for portability");
964 #if @GNULIB_STRVERSCMP@
965 # if !@HAVE_STRVERSCMP@
966 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
967 _GL_ARG_NONNULL ((1, 2)));
969 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
970 _GL_CXXALIASWARN (strverscmp);
971 #elif defined GNULIB_POSIXCHECK
973 # if HAVE_RAW_DECL_STRVERSCMP
974 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
975 "use gnulib module strverscmp for portability");
980 #endif /* _@GUARD_PREFIX@_STRING_H */
981 #endif /* _@GUARD_PREFIX@_STRING_H */