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. */
22 @PRAGMA_SYSTEM_HEADER@
26 /* The include_next requires a split double-inclusion guard. */
27 #@INCLUDE_NEXT@ @NEXT_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 ! @HAVE_STRCHRNUL@
281 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
283 _GL_ARG_NONNULL ((1)));
285 /* On some systems, this function is defined as an overloaded function:
286 extern "C++" { const char * std::strchrnul (const char *, int); }
287 extern "C++" { char * std::strchrnul (char *, int); } */
288 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
289 char *, (char const *__s, int __c_in),
290 char const *, (char const *__s, int __c_in));
291 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
292 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
293 _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
294 _GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
296 _GL_CXXALIASWARN (strchrnul);
298 #elif defined GNULIB_POSIXCHECK
300 # if HAVE_RAW_DECL_STRCHRNUL
301 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
302 "use gnulib module strchrnul for portability");
306 /* Duplicate S, returning an identical malloc'd string. */
308 # if @REPLACE_STRDUP@
309 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
311 # define strdup rpl_strdup
313 _GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
314 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
316 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
317 /* strdup exists as a function and as a macro. Get rid of the macro. */
320 # if !(@HAVE_DECL_STRDUP@ || defined strdup)
321 _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1)));
323 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
325 _GL_CXXALIASWARN (strdup);
326 #elif defined GNULIB_POSIXCHECK
328 # if HAVE_RAW_DECL_STRDUP
329 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
330 "use gnulib module strdup for portability");
334 /* Append no more than N characters from SRC onto DEST. */
336 # if @REPLACE_STRNCAT@
337 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
339 # define strncat rpl_strncat
341 _GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n)
342 _GL_ARG_NONNULL ((1, 2)));
343 _GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n));
345 _GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n));
347 _GL_CXXALIASWARN (strncat);
348 #elif defined GNULIB_POSIXCHECK
350 # if HAVE_RAW_DECL_STRNCAT
351 _GL_WARN_ON_USE (strncat, "strncat is unportable - "
352 "use gnulib module strncat for portability");
356 /* Return a newly allocated copy of at most N bytes of STRING. */
358 # if @REPLACE_STRNDUP@
359 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
361 # define strndup rpl_strndup
363 _GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n)
364 _GL_ARG_NONNULL ((1)));
365 _GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n));
367 # if ! @HAVE_DECL_STRNDUP@
368 _GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n)
369 _GL_ARG_NONNULL ((1)));
371 _GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n));
373 _GL_CXXALIASWARN (strndup);
374 #elif defined GNULIB_POSIXCHECK
376 # if HAVE_RAW_DECL_STRNDUP
377 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
378 "use gnulib module strndup for portability");
382 /* Find the length (number of bytes) of STRING, but scan at most
383 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
386 # if @REPLACE_STRNLEN@
387 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
389 # define strnlen rpl_strnlen
391 _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
393 _GL_ARG_NONNULL ((1)));
394 _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
396 # if ! @HAVE_DECL_STRNLEN@
397 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
399 _GL_ARG_NONNULL ((1)));
401 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
403 _GL_CXXALIASWARN (strnlen);
404 #elif defined GNULIB_POSIXCHECK
406 # if HAVE_RAW_DECL_STRNLEN
407 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
408 "use gnulib module strnlen for portability");
412 #if defined GNULIB_POSIXCHECK
413 /* strcspn() assumes the second argument is a list of single-byte characters.
414 Even in this simple case, it does not work with multibyte strings if the
415 locale encoding is GB18030 and one of the characters to be searched is a
418 /* Assume strcspn is always declared. */
419 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
420 "in multibyte locales - "
421 "use mbscspn if you care about internationalization");
424 /* Find the first occurrence in S of any character in ACCEPT. */
426 # if ! @HAVE_STRPBRK@
427 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
429 _GL_ARG_NONNULL ((1, 2)));
431 /* On some systems, this function is defined as an overloaded function:
432 extern "C" { const char * strpbrk (const char *, const char *); }
433 extern "C++" { char * strpbrk (char *, const char *); } */
434 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
435 char *, (char const *__s, char const *__accept),
436 const char *, (char const *__s, char const *__accept));
437 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
438 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
439 _GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
440 _GL_CXXALIASWARN1 (strpbrk, char const *,
441 (char const *__s, char const *__accept));
443 _GL_CXXALIASWARN (strpbrk);
445 # if defined GNULIB_POSIXCHECK
446 /* strpbrk() assumes the second argument is a list of single-byte characters.
447 Even in this simple case, it does not work with multibyte strings if the
448 locale encoding is GB18030 and one of the characters to be searched is a
451 _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
452 "in multibyte locales - "
453 "use mbspbrk if you care about internationalization");
455 #elif defined GNULIB_POSIXCHECK
457 # if HAVE_RAW_DECL_STRPBRK
458 _GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
459 "use gnulib module strpbrk for portability");
463 #if defined GNULIB_POSIXCHECK
464 /* strspn() assumes the second argument is a list of single-byte characters.
465 Even in this simple case, it cannot work with multibyte strings. */
467 /* Assume strspn is always declared. */
468 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
469 "in multibyte locales - "
470 "use mbsspn if you care about internationalization");
473 #if defined GNULIB_POSIXCHECK
474 /* strrchr() does not work with multibyte strings if the locale encoding is
475 GB18030 and the character to be searched is a digit. */
477 /* Assume strrchr is always declared. */
478 _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
479 "in some multibyte locales - "
480 "use mbsrchr if you care about internationalization");
483 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
484 If one is found, overwrite it with a NUL, and advance *STRINGP
485 to point to the next char after it. Otherwise, set *STRINGP to NULL.
486 If *STRINGP was already NULL, nothing happens.
487 Return the old value of *STRINGP.
489 This is a variant of strtok() that is multithread-safe and supports
492 Caveat: It modifies the original string.
493 Caveat: These functions cannot be used on constant strings.
494 Caveat: The identity of the delimiting character is lost.
495 Caveat: It doesn't work with multibyte strings unless all of the delimiter
496 characters are ASCII characters < 0x30.
498 See also strtok_r(). */
501 _GL_FUNCDECL_SYS (strsep, char *,
502 (char **restrict __stringp, char const *restrict __delim)
503 _GL_ARG_NONNULL ((1, 2)));
505 _GL_CXXALIAS_SYS (strsep, char *,
506 (char **restrict __stringp, char const *restrict __delim));
507 _GL_CXXALIASWARN (strsep);
508 # if defined GNULIB_POSIXCHECK
510 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
511 "in multibyte locales - "
512 "use mbssep if you care about internationalization");
514 #elif defined GNULIB_POSIXCHECK
516 # if HAVE_RAW_DECL_STRSEP
517 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
518 "use gnulib module strsep for portability");
523 # if @REPLACE_STRSTR@
524 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
525 # define strstr rpl_strstr
527 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
529 _GL_ARG_NONNULL ((1, 2)));
530 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
532 /* On some systems, this function is defined as an overloaded function:
533 extern "C++" { const char * strstr (const char *, const char *); }
534 extern "C++" { char * strstr (char *, const char *); } */
535 _GL_CXXALIAS_SYS_CAST2 (strstr,
536 char *, (const char *haystack, const char *needle),
537 const char *, (const char *haystack, const char *needle));
539 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
540 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
541 _GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
542 _GL_CXXALIASWARN1 (strstr, const char *,
543 (const char *haystack, const char *needle));
545 _GL_CXXALIASWARN (strstr);
547 #elif defined GNULIB_POSIXCHECK
548 /* strstr() does not work with multibyte strings if the locale encoding is
549 different from UTF-8:
550 POSIX says that it operates on "strings", and "string" in POSIX is defined
551 as a sequence of bytes, not of characters. */
553 /* Assume strstr is always declared. */
554 _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
555 "work correctly on character strings in most "
556 "multibyte locales - "
557 "use mbsstr if you care about internationalization, "
558 "or use strstr if you care about speed");
561 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
563 #if @GNULIB_STRCASESTR@
564 # if @REPLACE_STRCASESTR@
565 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
566 # define strcasestr rpl_strcasestr
568 _GL_FUNCDECL_RPL (strcasestr, char *,
569 (const char *haystack, const char *needle)
571 _GL_ARG_NONNULL ((1, 2)));
572 _GL_CXXALIAS_RPL (strcasestr, char *,
573 (const char *haystack, const char *needle));
575 # if ! @HAVE_STRCASESTR@
576 _GL_FUNCDECL_SYS (strcasestr, char *,
577 (const char *haystack, const char *needle)
579 _GL_ARG_NONNULL ((1, 2)));
581 /* On some systems, this function is defined as an overloaded function:
582 extern "C++" { const char * strcasestr (const char *, const char *); }
583 extern "C++" { char * strcasestr (char *, const char *); } */
584 _GL_CXXALIAS_SYS_CAST2 (strcasestr,
585 char *, (const char *haystack, const char *needle),
586 const char *, (const char *haystack, const char *needle));
588 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
589 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
590 _GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
591 _GL_CXXALIASWARN1 (strcasestr, const char *,
592 (const char *haystack, const char *needle));
594 _GL_CXXALIASWARN (strcasestr);
596 #elif defined GNULIB_POSIXCHECK
597 /* strcasestr() does not work with multibyte strings:
598 It is a glibc extension, and glibc implements it only for unibyte
601 # if HAVE_RAW_DECL_STRCASESTR
602 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
603 "strings in multibyte locales - "
604 "use mbscasestr if you care about "
605 "internationalization, or use c-strcasestr if you want "
606 "a locale independent function");
610 /* Parse S into tokens separated by characters in DELIM.
611 If S is NULL, the saved pointer in SAVE_PTR is used as
612 the next starting point. For example:
613 char s[] = "-abc-=-def";
615 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
616 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
617 x = strtok_r(NULL, "=", &sp); // x = NULL
620 This is a variant of strtok() that is multithread-safe.
622 For the POSIX documentation for this function, see:
623 http://www.opengroup.org/susv3xsh/strtok.html
625 Caveat: It modifies the original string.
626 Caveat: These functions cannot be used on constant strings.
627 Caveat: The identity of the delimiting character is lost.
628 Caveat: It doesn't work with multibyte strings unless all of the delimiter
629 characters are ASCII characters < 0x30.
631 See also strsep(). */
632 #if @GNULIB_STRTOK_R@
633 # if @REPLACE_STRTOK_R@
634 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
636 # define strtok_r rpl_strtok_r
638 _GL_FUNCDECL_RPL (strtok_r, char *,
639 (char *restrict s, char const *restrict delim,
640 char **restrict save_ptr)
641 _GL_ARG_NONNULL ((2, 3)));
642 _GL_CXXALIAS_RPL (strtok_r, char *,
643 (char *restrict s, char const *restrict delim,
644 char **restrict save_ptr));
646 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
649 # if ! @HAVE_DECL_STRTOK_R@
650 _GL_FUNCDECL_SYS (strtok_r, char *,
651 (char *restrict s, char const *restrict delim,
652 char **restrict save_ptr)
653 _GL_ARG_NONNULL ((2, 3)));
655 _GL_CXXALIAS_SYS (strtok_r, char *,
656 (char *restrict s, char const *restrict delim,
657 char **restrict save_ptr));
659 _GL_CXXALIASWARN (strtok_r);
660 # if defined GNULIB_POSIXCHECK
661 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
662 "strings in multibyte locales - "
663 "use mbstok_r if you care about internationalization");
665 #elif defined GNULIB_POSIXCHECK
667 # if HAVE_RAW_DECL_STRTOK_R
668 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
669 "use gnulib module strtok_r for portability");
674 /* The following functions are not specified by POSIX. They are gnulib
678 /* Return the number of multibyte characters in the character string STRING.
679 This considers multibyte characters, unlike strlen, which counts bytes. */
680 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
683 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
684 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
685 # define mbslen rpl_mbslen
687 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
688 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
690 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1)));
691 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
693 _GL_CXXALIASWARN (mbslen);
697 /* Return the number of multibyte characters in the character string starting
698 at STRING and ending at STRING + LEN. */
699 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
700 _GL_ARG_NONNULL ((1));
704 /* Locate the first single-byte character C in the character string STRING,
705 and return a pointer to it. Return NULL if C is not found in STRING.
706 Unlike strchr(), this function works correctly in multibyte locales with
707 encodings such as GB18030. */
709 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
710 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
712 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
713 _GL_ARG_NONNULL ((1)));
714 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
716 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
717 _GL_ARG_NONNULL ((1)));
718 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
720 _GL_CXXALIASWARN (mbschr);
724 /* Locate the last single-byte character C in the character string STRING,
725 and return a pointer to it. Return NULL if C is not found in STRING.
726 Unlike strrchr(), this function works correctly in multibyte locales with
727 encodings such as GB18030. */
729 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
730 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
732 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
733 _GL_ARG_NONNULL ((1)));
734 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
736 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
737 _GL_ARG_NONNULL ((1)));
738 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
740 _GL_CXXALIASWARN (mbsrchr);
744 /* Find the first occurrence of the character string NEEDLE in the character
745 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
746 Unlike strstr(), this function works correctly in multibyte locales with
747 encodings different from UTF-8. */
748 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
749 _GL_ARG_NONNULL ((1, 2));
752 #if @GNULIB_MBSCASECMP@
753 /* Compare the character strings S1 and S2, ignoring case, returning less than,
754 equal to or greater than zero if S1 is lexicographically less than, equal to
756 Note: This function may, in multibyte locales, return 0 for strings of
758 Unlike strcasecmp(), this function works correctly in multibyte locales. */
759 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
760 _GL_ARG_NONNULL ((1, 2));
763 #if @GNULIB_MBSNCASECMP@
764 /* Compare the initial segment of the character string S1 consisting of at most
765 N characters with the initial segment of the character string S2 consisting
766 of at most N characters, ignoring case, returning less than, equal to or
767 greater than zero if the initial segment of S1 is lexicographically less
768 than, equal to or greater than the initial segment of S2.
769 Note: This function may, in multibyte locales, return 0 for initial segments
770 of different lengths!
771 Unlike strncasecmp(), this function works correctly in multibyte locales.
772 But beware that N is not a byte count but a character count! */
773 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
774 _GL_ARG_NONNULL ((1, 2));
777 #if @GNULIB_MBSPCASECMP@
778 /* Compare the initial segment of the character string STRING consisting of
779 at most mbslen (PREFIX) characters with the character string PREFIX,
780 ignoring case. If the two match, return a pointer to the first byte
781 after this prefix in STRING. Otherwise, return NULL.
782 Note: This function may, in multibyte locales, return non-NULL if STRING
783 is of smaller length than PREFIX!
784 Unlike strncasecmp(), this function works correctly in multibyte
786 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
787 _GL_ARG_NONNULL ((1, 2));
790 #if @GNULIB_MBSCASESTR@
791 /* Find the first occurrence of the character string NEEDLE in the character
792 string HAYSTACK, using case-insensitive comparison.
793 Note: This function may, in multibyte locales, return success even if
794 strlen (haystack) < strlen (needle) !
795 Unlike strcasestr(), this function works correctly in multibyte locales. */
796 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
797 _GL_ARG_NONNULL ((1, 2));
801 /* Find the first occurrence in the character string STRING of any character
802 in the character string ACCEPT. Return the number of bytes from the
803 beginning of the string to this occurrence, or to the end of the string
805 Unlike strcspn(), this function works correctly in multibyte locales. */
806 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
807 _GL_ARG_NONNULL ((1, 2));
811 /* Find the first occurrence in the character string STRING of any character
812 in the character string ACCEPT. Return the pointer to it, or NULL if none
814 Unlike strpbrk(), this function works correctly in multibyte locales. */
816 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
817 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
819 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
820 _GL_ARG_NONNULL ((1, 2)));
821 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
823 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
824 _GL_ARG_NONNULL ((1, 2)));
825 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
827 _GL_CXXALIASWARN (mbspbrk);
831 /* Find the first occurrence in the character string STRING of any character
832 not in the character string REJECT. Return the number of bytes from the
833 beginning of the string to this occurrence, or to the end of the string
835 Unlike strspn(), this function works correctly in multibyte locales. */
836 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
837 _GL_ARG_NONNULL ((1, 2));
841 /* Search the next delimiter (multibyte character listed in the character
842 string DELIM) starting at the character string *STRINGP.
843 If one is found, overwrite it with a NUL, and advance *STRINGP to point
844 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
845 If *STRINGP was already NULL, nothing happens.
846 Return the old value of *STRINGP.
848 This is a variant of mbstok_r() that supports empty fields.
850 Caveat: It modifies the original string.
851 Caveat: These functions cannot be used on constant strings.
852 Caveat: The identity of the delimiting character is lost.
854 See also mbstok_r(). */
855 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
856 _GL_ARG_NONNULL ((1, 2));
859 #if @GNULIB_MBSTOK_R@
860 /* Parse the character string STRING into tokens separated by characters in
861 the character string DELIM.
862 If STRING is NULL, the saved pointer in SAVE_PTR is used as
863 the next starting point. For example:
864 char s[] = "-abc-=-def";
866 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
867 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
868 x = mbstok_r(NULL, "=", &sp); // x = NULL
871 Caveat: It modifies the original string.
872 Caveat: These functions cannot be used on constant strings.
873 Caveat: The identity of the delimiting character is lost.
875 See also mbssep(). */
876 _GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr)
877 _GL_ARG_NONNULL ((2, 3));
880 /* Map any int, typically from errno, into an error message. */
881 #if @GNULIB_STRERROR@
882 # if @REPLACE_STRERROR@
883 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
885 # define strerror rpl_strerror
887 _GL_FUNCDECL_RPL (strerror, char *, (int));
888 _GL_CXXALIAS_RPL (strerror, char *, (int));
890 _GL_CXXALIAS_SYS (strerror, char *, (int));
892 _GL_CXXALIASWARN (strerror);
893 #elif defined GNULIB_POSIXCHECK
895 /* Assume strerror is always declared. */
896 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
897 "use gnulib module strerror to guarantee non-NULL result");
900 /* Map any int, typically from errno, into an error message. Multithread-safe.
901 Uses the POSIX declaration, not the glibc declaration. */
902 #if @GNULIB_STRERROR_R@
903 # if @REPLACE_STRERROR_R@
904 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
906 # define strerror_r rpl_strerror_r
908 _GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)
909 _GL_ARG_NONNULL ((2)));
910 _GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
912 # if !@HAVE_DECL_STRERROR_R@
913 _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)
914 _GL_ARG_NONNULL ((2)));
916 _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
918 # if @HAVE_DECL_STRERROR_R@
919 _GL_CXXALIASWARN (strerror_r);
921 #elif defined GNULIB_POSIXCHECK
923 # if HAVE_RAW_DECL_STRERROR_R
924 _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
925 "use gnulib module strerror_r-posix for portability");
929 #if @GNULIB_STRSIGNAL@
930 # if @REPLACE_STRSIGNAL@
931 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
932 # define strsignal rpl_strsignal
934 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
935 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
937 # if ! @HAVE_DECL_STRSIGNAL@
938 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
940 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
942 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
944 _GL_CXXALIASWARN (strsignal);
945 #elif defined GNULIB_POSIXCHECK
947 # if HAVE_RAW_DECL_STRSIGNAL
948 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
949 "use gnulib module strsignal for portability");
953 #if @GNULIB_STRVERSCMP@
954 # if !@HAVE_STRVERSCMP@
955 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
956 _GL_ARG_NONNULL ((1, 2)));
958 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
959 _GL_CXXALIASWARN (strverscmp);
960 #elif defined GNULIB_POSIXCHECK
962 # if HAVE_RAW_DECL_STRVERSCMP
963 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
964 "use gnulib module strverscmp for portability");
969 #endif /* _GL_STRING_H */
970 #endif /* _GL_STRING_H */