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-2011 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
24 @PRAGMA_SYSTEM_HEADER@
28 /* The include_next requires a split double-inclusion guard. */
29 #@INCLUDE_NEXT@ @NEXT_STRING_H@
34 /* NetBSD 5.0 mis-defines NULL. */
37 /* MirBSD defines mbslen as a macro. */
38 #if @GNULIB_MBSLEN@ && defined __MirBSD__
42 /* The __attribute__ feature is available in gcc versions 2.5 and later.
43 The attribute __pure__ was added in gcc 2.96. */
44 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
45 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
47 # define _GL_ATTRIBUTE_PURE /* empty */
50 /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
51 /* But in any case avoid namespace pollution on glibc systems. */
52 #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
53 && ! defined __GLIBC__
57 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
59 /* The definition of _GL_ARG_NONNULL is copied here. */
61 /* The definition of _GL_WARN_ON_USE is copied here. */
64 /* Return the first instance of C within N bytes of S, or NULL. */
67 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
68 # define memchr rpl_memchr
70 _GL_FUNCDECL_RPL (memchr
, void *, (void const *__s
, int __c
, size_t __n
)
72 _GL_ARG_NONNULL ((1)));
73 _GL_CXXALIAS_RPL (memchr
, void *, (void const *__s
, int __c
, size_t __n
));
76 _GL_FUNCDECL_SYS (memchr
, void *, (void const *__s
, int __c
, size_t __n
)
78 _GL_ARG_NONNULL ((1)));
80 /* On some systems, this function is defined as an overloaded function:
81 extern "C" { const void * std::memchr (const void *, int, size_t); }
82 extern "C++" { void * std::memchr (void *, int, size_t); } */
83 _GL_CXXALIAS_SYS_CAST2 (memchr
,
84 void *, (void const *__s
, int __c
, size_t __n
),
85 void const *, (void const *__s
, int __c
, size_t __n
));
87 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
88 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
89 _GL_CXXALIASWARN1 (memchr
, void *, (void *__s
, int __c
, size_t __n
));
90 _GL_CXXALIASWARN1 (memchr
, void const *,
91 (void const *__s
, int __c
, size_t __n
));
93 _GL_CXXALIASWARN (memchr
);
95 #elif defined GNULIB_POSIXCHECK
97 /* Assume memchr is always declared. */
98 _GL_WARN_ON_USE (memchr
, "memchr has platform-specific bugs - "
99 "use gnulib module memchr for portability" );
102 /* Return the first occurrence of NEEDLE in HAYSTACK. */
104 # if @REPLACE_MEMMEM@
105 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
106 # define memmem rpl_memmem
108 _GL_FUNCDECL_RPL (memmem
, void *,
109 (void const *__haystack
, size_t __haystack_len
,
110 void const *__needle
, size_t __needle_len
)
112 _GL_ARG_NONNULL ((1, 3)));
113 _GL_CXXALIAS_RPL (memmem
, void *,
114 (void const *__haystack
, size_t __haystack_len
,
115 void const *__needle
, size_t __needle_len
));
117 # if ! @HAVE_DECL_MEMMEM@
118 _GL_FUNCDECL_SYS (memmem
, void *,
119 (void const *__haystack
, size_t __haystack_len
,
120 void const *__needle
, size_t __needle_len
)
122 _GL_ARG_NONNULL ((1, 3)));
124 _GL_CXXALIAS_SYS (memmem
, void *,
125 (void const *__haystack
, size_t __haystack_len
,
126 void const *__needle
, size_t __needle_len
));
128 _GL_CXXALIASWARN (memmem
);
129 #elif defined GNULIB_POSIXCHECK
131 # if HAVE_RAW_DECL_MEMMEM
132 _GL_WARN_ON_USE (memmem
, "memmem is unportable and often quadratic - "
133 "use gnulib module memmem-simple for portability, "
134 "and module memmem for speed" );
138 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
139 last written byte. */
141 # if ! @HAVE_MEMPCPY@
142 _GL_FUNCDECL_SYS (mempcpy
, void *,
143 (void *restrict __dest
, void const *restrict __src
,
145 _GL_ARG_NONNULL ((1, 2)));
147 _GL_CXXALIAS_SYS (mempcpy
, void *,
148 (void *restrict __dest
, void const *restrict __src
,
150 _GL_CXXALIASWARN (mempcpy
);
151 #elif defined GNULIB_POSIXCHECK
153 # if HAVE_RAW_DECL_MEMPCPY
154 _GL_WARN_ON_USE (mempcpy
, "mempcpy is unportable - "
155 "use gnulib module mempcpy for portability");
159 /* Search backwards through a block for a byte (specified as an int). */
161 # if ! @HAVE_DECL_MEMRCHR@
162 _GL_FUNCDECL_SYS (memrchr
, void *, (void const *, int, size_t)
164 _GL_ARG_NONNULL ((1)));
166 /* On some systems, this function is defined as an overloaded function:
167 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
168 extern "C++" { void * std::memrchr (void *, int, size_t); } */
169 _GL_CXXALIAS_SYS_CAST2 (memrchr
,
170 void *, (void const *, int, size_t),
171 void const *, (void const *, int, size_t));
172 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
173 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
174 _GL_CXXALIASWARN1 (memrchr
, void *, (void *, int, size_t));
175 _GL_CXXALIASWARN1 (memrchr
, void const *, (void const *, int, size_t));
177 _GL_CXXALIASWARN (memrchr
);
179 #elif defined GNULIB_POSIXCHECK
181 # if HAVE_RAW_DECL_MEMRCHR
182 _GL_WARN_ON_USE (memrchr
, "memrchr is unportable - "
183 "use gnulib module memrchr for portability");
187 /* Find the first occurrence of C in S. More efficient than
188 memchr(S,C,N), at the expense of undefined behavior if C does not
189 occur within N bytes. */
190 #if @GNULIB_RAWMEMCHR@
191 # if ! @HAVE_RAWMEMCHR@
192 _GL_FUNCDECL_SYS (rawmemchr
, void *, (void const *__s
, int __c_in
)
194 _GL_ARG_NONNULL ((1)));
196 /* On some systems, this function is defined as an overloaded function:
197 extern "C++" { const void * std::rawmemchr (const void *, int); }
198 extern "C++" { void * std::rawmemchr (void *, int); } */
199 _GL_CXXALIAS_SYS_CAST2 (rawmemchr
,
200 void *, (void const *__s
, int __c_in
),
201 void const *, (void const *__s
, int __c_in
));
202 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
203 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
204 _GL_CXXALIASWARN1 (rawmemchr
, void *, (void *__s
, int __c_in
));
205 _GL_CXXALIASWARN1 (rawmemchr
, void const *, (void const *__s
, int __c_in
));
207 _GL_CXXALIASWARN (rawmemchr
);
209 #elif defined GNULIB_POSIXCHECK
211 # if HAVE_RAW_DECL_RAWMEMCHR
212 _GL_WARN_ON_USE (rawmemchr
, "rawmemchr is unportable - "
213 "use gnulib module rawmemchr for portability");
217 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
220 _GL_FUNCDECL_SYS (stpcpy
, char *,
221 (char *restrict __dst
, char const *restrict __src
)
222 _GL_ARG_NONNULL ((1, 2)));
224 _GL_CXXALIAS_SYS (stpcpy
, char *,
225 (char *restrict __dst
, char const *restrict __src
));
226 _GL_CXXALIASWARN (stpcpy
);
227 #elif defined GNULIB_POSIXCHECK
229 # if HAVE_RAW_DECL_STPCPY
230 _GL_WARN_ON_USE (stpcpy
, "stpcpy is unportable - "
231 "use gnulib module stpcpy for portability");
235 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
236 last non-NUL byte written into DST. */
238 # if @REPLACE_STPNCPY@
239 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
241 # define stpncpy rpl_stpncpy
243 _GL_FUNCDECL_RPL (stpncpy
, char *,
244 (char *restrict __dst
, char const *restrict __src
,
246 _GL_ARG_NONNULL ((1, 2)));
247 _GL_CXXALIAS_RPL (stpncpy
, char *,
248 (char *restrict __dst
, char const *restrict __src
,
251 # if ! @HAVE_STPNCPY@
252 _GL_FUNCDECL_SYS (stpncpy
, char *,
253 (char *restrict __dst
, char const *restrict __src
,
255 _GL_ARG_NONNULL ((1, 2)));
257 _GL_CXXALIAS_SYS (stpncpy
, char *,
258 (char *restrict __dst
, char const *restrict __src
,
261 _GL_CXXALIASWARN (stpncpy
);
262 #elif defined GNULIB_POSIXCHECK
264 # if HAVE_RAW_DECL_STPNCPY
265 _GL_WARN_ON_USE (stpncpy
, "stpncpy is unportable - "
266 "use gnulib module stpncpy for portability");
270 #if defined GNULIB_POSIXCHECK
271 /* strchr() does not work with multibyte strings if the locale encoding is
272 GB18030 and the character to be searched is a digit. */
274 /* Assume strchr is always declared. */
275 _GL_WARN_ON_USE (strchr
, "strchr cannot work correctly on character strings "
276 "in some multibyte locales - "
277 "use mbschr if you care about internationalization");
280 /* Find the first occurrence of C in S or the final NUL byte. */
281 #if @GNULIB_STRCHRNUL@
282 # if ! @HAVE_STRCHRNUL@
283 _GL_FUNCDECL_SYS (strchrnul
, char *, (char const *__s
, int __c_in
)
285 _GL_ARG_NONNULL ((1)));
287 /* On some systems, this function is defined as an overloaded function:
288 extern "C++" { const char * std::strchrnul (const char *, int); }
289 extern "C++" { char * std::strchrnul (char *, int); } */
290 _GL_CXXALIAS_SYS_CAST2 (strchrnul
,
291 char *, (char const *__s
, int __c_in
),
292 char const *, (char const *__s
, int __c_in
));
293 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
294 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
295 _GL_CXXALIASWARN1 (strchrnul
, char *, (char *__s
, int __c_in
));
296 _GL_CXXALIASWARN1 (strchrnul
, char const *, (char const *__s
, int __c_in
));
298 _GL_CXXALIASWARN (strchrnul
);
300 #elif defined GNULIB_POSIXCHECK
302 # if HAVE_RAW_DECL_STRCHRNUL
303 _GL_WARN_ON_USE (strchrnul
, "strchrnul is unportable - "
304 "use gnulib module strchrnul for portability");
308 /* Duplicate S, returning an identical malloc'd string. */
310 # if @REPLACE_STRDUP@
311 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
313 # define strdup rpl_strdup
315 _GL_FUNCDECL_RPL (strdup
, char *, (char const *__s
) _GL_ARG_NONNULL ((1)));
316 _GL_CXXALIAS_RPL (strdup
, char *, (char const *__s
));
318 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
319 /* strdup exists as a function and as a macro. Get rid of the macro. */
322 # if !(@HAVE_DECL_STRDUP@ || defined strdup)
323 _GL_FUNCDECL_SYS (strdup
, char *, (char const *__s
) _GL_ARG_NONNULL ((1)));
325 _GL_CXXALIAS_SYS (strdup
, char *, (char const *__s
));
327 _GL_CXXALIASWARN (strdup
);
328 #elif defined GNULIB_POSIXCHECK
330 # if HAVE_RAW_DECL_STRDUP
331 _GL_WARN_ON_USE (strdup
, "strdup is unportable - "
332 "use gnulib module strdup for portability");
336 /* Append no more than N characters from SRC onto DEST. */
338 # if @REPLACE_STRNCAT@
339 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
341 # define strncat rpl_strncat
343 _GL_FUNCDECL_RPL (strncat
, char *, (char *dest
, const char *src
, size_t n
)
344 _GL_ARG_NONNULL ((1, 2)));
345 _GL_CXXALIAS_RPL (strncat
, char *, (char *dest
, const char *src
, size_t n
));
347 _GL_CXXALIAS_SYS (strncat
, char *, (char *dest
, const char *src
, size_t n
));
349 _GL_CXXALIASWARN (strncat
);
350 #elif defined GNULIB_POSIXCHECK
352 # if HAVE_RAW_DECL_STRNCAT
353 _GL_WARN_ON_USE (strncat
, "strncat is unportable - "
354 "use gnulib module strncat for portability");
358 /* Return a newly allocated copy of at most N bytes of STRING. */
360 # if @REPLACE_STRNDUP@
361 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
363 # define strndup rpl_strndup
365 _GL_FUNCDECL_RPL (strndup
, char *, (char const *__string
, size_t __n
)
366 _GL_ARG_NONNULL ((1)));
367 _GL_CXXALIAS_RPL (strndup
, char *, (char const *__string
, size_t __n
));
369 # if ! @HAVE_DECL_STRNDUP@
370 _GL_FUNCDECL_SYS (strndup
, char *, (char const *__string
, size_t __n
)
371 _GL_ARG_NONNULL ((1)));
373 _GL_CXXALIAS_SYS (strndup
, char *, (char const *__string
, size_t __n
));
375 _GL_CXXALIASWARN (strndup
);
376 #elif defined GNULIB_POSIXCHECK
378 # if HAVE_RAW_DECL_STRNDUP
379 _GL_WARN_ON_USE (strndup
, "strndup is unportable - "
380 "use gnulib module strndup for portability");
384 /* Find the length (number of bytes) of STRING, but scan at most
385 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
388 # if @REPLACE_STRNLEN@
389 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
391 # define strnlen rpl_strnlen
393 _GL_FUNCDECL_RPL (strnlen
, size_t, (char const *__string
, size_t __maxlen
)
395 _GL_ARG_NONNULL ((1)));
396 _GL_CXXALIAS_RPL (strnlen
, size_t, (char const *__string
, size_t __maxlen
));
398 # if ! @HAVE_DECL_STRNLEN@
399 _GL_FUNCDECL_SYS (strnlen
, size_t, (char const *__string
, size_t __maxlen
)
401 _GL_ARG_NONNULL ((1)));
403 _GL_CXXALIAS_SYS (strnlen
, size_t, (char const *__string
, size_t __maxlen
));
405 _GL_CXXALIASWARN (strnlen
);
406 #elif defined GNULIB_POSIXCHECK
408 # if HAVE_RAW_DECL_STRNLEN
409 _GL_WARN_ON_USE (strnlen
, "strnlen is unportable - "
410 "use gnulib module strnlen for portability");
414 #if defined GNULIB_POSIXCHECK
415 /* strcspn() assumes the second argument is a list of single-byte characters.
416 Even in this simple case, it does not work with multibyte strings if the
417 locale encoding is GB18030 and one of the characters to be searched is a
420 /* Assume strcspn is always declared. */
421 _GL_WARN_ON_USE (strcspn
, "strcspn cannot work correctly on character strings "
422 "in multibyte locales - "
423 "use mbscspn if you care about internationalization");
426 /* Find the first occurrence in S of any character in ACCEPT. */
428 # if ! @HAVE_STRPBRK@
429 _GL_FUNCDECL_SYS (strpbrk
, char *, (char const *__s
, char const *__accept
)
431 _GL_ARG_NONNULL ((1, 2)));
433 /* On some systems, this function is defined as an overloaded function:
434 extern "C" { const char * strpbrk (const char *, const char *); }
435 extern "C++" { char * strpbrk (char *, const char *); } */
436 _GL_CXXALIAS_SYS_CAST2 (strpbrk
,
437 char *, (char const *__s
, char const *__accept
),
438 const char *, (char const *__s
, char const *__accept
));
439 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
440 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
441 _GL_CXXALIASWARN1 (strpbrk
, char *, (char *__s
, char const *__accept
));
442 _GL_CXXALIASWARN1 (strpbrk
, char const *,
443 (char const *__s
, char const *__accept
));
445 _GL_CXXALIASWARN (strpbrk
);
447 # if defined GNULIB_POSIXCHECK
448 /* strpbrk() assumes the second argument is a list of single-byte characters.
449 Even in this simple case, it does not work with multibyte strings if the
450 locale encoding is GB18030 and one of the characters to be searched is a
453 _GL_WARN_ON_USE (strpbrk
, "strpbrk cannot work correctly on character strings "
454 "in multibyte locales - "
455 "use mbspbrk if you care about internationalization");
457 #elif defined GNULIB_POSIXCHECK
459 # if HAVE_RAW_DECL_STRPBRK
460 _GL_WARN_ON_USE (strpbrk
, "strpbrk is unportable - "
461 "use gnulib module strpbrk for portability");
465 #if defined GNULIB_POSIXCHECK
466 /* strspn() assumes the second argument is a list of single-byte characters.
467 Even in this simple case, it cannot work with multibyte strings. */
469 /* Assume strspn is always declared. */
470 _GL_WARN_ON_USE (strspn
, "strspn cannot work correctly on character strings "
471 "in multibyte locales - "
472 "use mbsspn if you care about internationalization");
475 #if defined GNULIB_POSIXCHECK
476 /* strrchr() does not work with multibyte strings if the locale encoding is
477 GB18030 and the character to be searched is a digit. */
479 /* Assume strrchr is always declared. */
480 _GL_WARN_ON_USE (strrchr
, "strrchr cannot work correctly on character strings "
481 "in some multibyte locales - "
482 "use mbsrchr if you care about internationalization");
485 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
486 If one is found, overwrite it with a NUL, and advance *STRINGP
487 to point to the next char after it. Otherwise, set *STRINGP to NULL.
488 If *STRINGP was already NULL, nothing happens.
489 Return the old value of *STRINGP.
491 This is a variant of strtok() that is multithread-safe and supports
494 Caveat: It modifies the original string.
495 Caveat: These functions cannot be used on constant strings.
496 Caveat: The identity of the delimiting character is lost.
497 Caveat: It doesn't work with multibyte strings unless all of the delimiter
498 characters are ASCII characters < 0x30.
500 See also strtok_r(). */
503 _GL_FUNCDECL_SYS (strsep
, char *,
504 (char **restrict __stringp
, char const *restrict __delim
)
505 _GL_ARG_NONNULL ((1, 2)));
507 _GL_CXXALIAS_SYS (strsep
, char *,
508 (char **restrict __stringp
, char const *restrict __delim
));
509 _GL_CXXALIASWARN (strsep
);
510 # if defined GNULIB_POSIXCHECK
512 _GL_WARN_ON_USE (strsep
, "strsep cannot work correctly on character strings "
513 "in multibyte locales - "
514 "use mbssep if you care about internationalization");
516 #elif defined GNULIB_POSIXCHECK
518 # if HAVE_RAW_DECL_STRSEP
519 _GL_WARN_ON_USE (strsep
, "strsep is unportable - "
520 "use gnulib module strsep for portability");
525 # if @REPLACE_STRSTR@
526 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
527 # define strstr rpl_strstr
529 _GL_FUNCDECL_RPL (strstr
, char *, (const char *haystack
, const char *needle
)
531 _GL_ARG_NONNULL ((1, 2)));
532 _GL_CXXALIAS_RPL (strstr
, char *, (const char *haystack
, const char *needle
));
534 /* On some systems, this function is defined as an overloaded function:
535 extern "C++" { const char * strstr (const char *, const char *); }
536 extern "C++" { char * strstr (char *, const char *); } */
537 _GL_CXXALIAS_SYS_CAST2 (strstr
,
538 char *, (const char *haystack
, const char *needle
),
539 const char *, (const char *haystack
, const char *needle
));
541 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
542 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
543 _GL_CXXALIASWARN1 (strstr
, char *, (char *haystack
, const char *needle
));
544 _GL_CXXALIASWARN1 (strstr
, const char *,
545 (const char *haystack
, const char *needle
));
547 _GL_CXXALIASWARN (strstr
);
549 #elif defined GNULIB_POSIXCHECK
550 /* strstr() does not work with multibyte strings if the locale encoding is
551 different from UTF-8:
552 POSIX says that it operates on "strings", and "string" in POSIX is defined
553 as a sequence of bytes, not of characters. */
555 /* Assume strstr is always declared. */
556 _GL_WARN_ON_USE (strstr
, "strstr is quadratic on many systems, and cannot "
557 "work correctly on character strings in most "
558 "multibyte locales - "
559 "use mbsstr if you care about internationalization, "
560 "or use strstr if you care about speed");
563 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
565 #if @GNULIB_STRCASESTR@
566 # if @REPLACE_STRCASESTR@
567 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
568 # define strcasestr rpl_strcasestr
570 _GL_FUNCDECL_RPL (strcasestr
, char *,
571 (const char *haystack
, const char *needle
)
573 _GL_ARG_NONNULL ((1, 2)));
574 _GL_CXXALIAS_RPL (strcasestr
, char *,
575 (const char *haystack
, const char *needle
));
577 # if ! @HAVE_STRCASESTR@
578 _GL_FUNCDECL_SYS (strcasestr
, char *,
579 (const char *haystack
, const char *needle
)
581 _GL_ARG_NONNULL ((1, 2)));
583 /* On some systems, this function is defined as an overloaded function:
584 extern "C++" { const char * strcasestr (const char *, const char *); }
585 extern "C++" { char * strcasestr (char *, const char *); } */
586 _GL_CXXALIAS_SYS_CAST2 (strcasestr
,
587 char *, (const char *haystack
, const char *needle
),
588 const char *, (const char *haystack
, const char *needle
));
590 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
591 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
592 _GL_CXXALIASWARN1 (strcasestr
, char *, (char *haystack
, const char *needle
));
593 _GL_CXXALIASWARN1 (strcasestr
, const char *,
594 (const char *haystack
, const char *needle
));
596 _GL_CXXALIASWARN (strcasestr
);
598 #elif defined GNULIB_POSIXCHECK
599 /* strcasestr() does not work with multibyte strings:
600 It is a glibc extension, and glibc implements it only for unibyte
603 # if HAVE_RAW_DECL_STRCASESTR
604 _GL_WARN_ON_USE (strcasestr
, "strcasestr does work correctly on character "
605 "strings in multibyte locales - "
606 "use mbscasestr if you care about "
607 "internationalization, or use c-strcasestr if you want "
608 "a locale independent function");
612 /* Parse S into tokens separated by characters in DELIM.
613 If S is NULL, the saved pointer in SAVE_PTR is used as
614 the next starting point. For example:
615 char s[] = "-abc-=-def";
617 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
618 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
619 x = strtok_r(NULL, "=", &sp); // x = NULL
622 This is a variant of strtok() that is multithread-safe.
624 For the POSIX documentation for this function, see:
625 http://www.opengroup.org/susv3xsh/strtok.html
627 Caveat: It modifies the original string.
628 Caveat: These functions cannot be used on constant strings.
629 Caveat: The identity of the delimiting character is lost.
630 Caveat: It doesn't work with multibyte strings unless all of the delimiter
631 characters are ASCII characters < 0x30.
633 See also strsep(). */
634 #if @GNULIB_STRTOK_R@
635 # if @REPLACE_STRTOK_R@
636 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
638 # define strtok_r rpl_strtok_r
640 _GL_FUNCDECL_RPL (strtok_r
, char *,
641 (char *restrict s
, char const *restrict delim
,
642 char **restrict save_ptr
)
643 _GL_ARG_NONNULL ((2, 3)));
644 _GL_CXXALIAS_RPL (strtok_r
, char *,
645 (char *restrict s
, char const *restrict delim
,
646 char **restrict save_ptr
));
648 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
651 # if ! @HAVE_DECL_STRTOK_R@
652 _GL_FUNCDECL_SYS (strtok_r
, char *,
653 (char *restrict s
, char const *restrict delim
,
654 char **restrict save_ptr
)
655 _GL_ARG_NONNULL ((2, 3)));
657 _GL_CXXALIAS_SYS (strtok_r
, char *,
658 (char *restrict s
, char const *restrict delim
,
659 char **restrict save_ptr
));
661 _GL_CXXALIASWARN (strtok_r
);
662 # if defined GNULIB_POSIXCHECK
663 _GL_WARN_ON_USE (strtok_r
, "strtok_r cannot work correctly on character "
664 "strings in multibyte locales - "
665 "use mbstok_r if you care about internationalization");
667 #elif defined GNULIB_POSIXCHECK
669 # if HAVE_RAW_DECL_STRTOK_R
670 _GL_WARN_ON_USE (strtok_r
, "strtok_r is unportable - "
671 "use gnulib module strtok_r for portability");
676 /* The following functions are not specified by POSIX. They are gnulib
680 /* Return the number of multibyte characters in the character string STRING.
681 This considers multibyte characters, unlike strlen, which counts bytes. */
682 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
685 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
686 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
687 # define mbslen rpl_mbslen
689 _GL_FUNCDECL_RPL (mbslen
, size_t, (const char *string
) _GL_ARG_NONNULL ((1)));
690 _GL_CXXALIAS_RPL (mbslen
, size_t, (const char *string
));
692 _GL_FUNCDECL_SYS (mbslen
, size_t, (const char *string
) _GL_ARG_NONNULL ((1)));
693 _GL_CXXALIAS_SYS (mbslen
, size_t, (const char *string
));
695 _GL_CXXALIASWARN (mbslen
);
699 /* Return the number of multibyte characters in the character string starting
700 at STRING and ending at STRING + LEN. */
701 _GL_EXTERN_C
size_t mbsnlen (const char *string
, size_t len
)
702 _GL_ARG_NONNULL ((1));
706 /* Locate the first single-byte character C in the character string STRING,
707 and return a pointer to it. Return NULL if C is not found in STRING.
708 Unlike strchr(), this function works correctly in multibyte locales with
709 encodings such as GB18030. */
711 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
712 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
714 _GL_FUNCDECL_RPL (mbschr
, char *, (const char *string
, int c
)
715 _GL_ARG_NONNULL ((1)));
716 _GL_CXXALIAS_RPL (mbschr
, char *, (const char *string
, int c
));
718 _GL_FUNCDECL_SYS (mbschr
, char *, (const char *string
, int c
)
719 _GL_ARG_NONNULL ((1)));
720 _GL_CXXALIAS_SYS (mbschr
, char *, (const char *string
, int c
));
722 _GL_CXXALIASWARN (mbschr
);
726 /* Locate the last single-byte character C in the character string STRING,
727 and return a pointer to it. Return NULL if C is not found in STRING.
728 Unlike strrchr(), this function works correctly in multibyte locales with
729 encodings such as GB18030. */
731 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
732 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
734 _GL_FUNCDECL_RPL (mbsrchr
, char *, (const char *string
, int c
)
735 _GL_ARG_NONNULL ((1)));
736 _GL_CXXALIAS_RPL (mbsrchr
, char *, (const char *string
, int c
));
738 _GL_FUNCDECL_SYS (mbsrchr
, char *, (const char *string
, int c
)
739 _GL_ARG_NONNULL ((1)));
740 _GL_CXXALIAS_SYS (mbsrchr
, char *, (const char *string
, int c
));
742 _GL_CXXALIASWARN (mbsrchr
);
746 /* Find the first occurrence of the character string NEEDLE in the character
747 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
748 Unlike strstr(), this function works correctly in multibyte locales with
749 encodings different from UTF-8. */
750 _GL_EXTERN_C
char * mbsstr (const char *haystack
, const char *needle
)
751 _GL_ARG_NONNULL ((1, 2));
754 #if @GNULIB_MBSCASECMP@
755 /* Compare the character strings S1 and S2, ignoring case, returning less than,
756 equal to or greater than zero if S1 is lexicographically less than, equal to
758 Note: This function may, in multibyte locales, return 0 for strings of
760 Unlike strcasecmp(), this function works correctly in multibyte locales. */
761 _GL_EXTERN_C
int mbscasecmp (const char *s1
, const char *s2
)
762 _GL_ARG_NONNULL ((1, 2));
765 #if @GNULIB_MBSNCASECMP@
766 /* Compare the initial segment of the character string S1 consisting of at most
767 N characters with the initial segment of the character string S2 consisting
768 of at most N characters, ignoring case, returning less than, equal to or
769 greater than zero if the initial segment of S1 is lexicographically less
770 than, equal to or greater than the initial segment of S2.
771 Note: This function may, in multibyte locales, return 0 for initial segments
772 of different lengths!
773 Unlike strncasecmp(), this function works correctly in multibyte locales.
774 But beware that N is not a byte count but a character count! */
775 _GL_EXTERN_C
int mbsncasecmp (const char *s1
, const char *s2
, size_t n
)
776 _GL_ARG_NONNULL ((1, 2));
779 #if @GNULIB_MBSPCASECMP@
780 /* Compare the initial segment of the character string STRING consisting of
781 at most mbslen (PREFIX) characters with the character string PREFIX,
782 ignoring case. If the two match, return a pointer to the first byte
783 after this prefix in STRING. Otherwise, return NULL.
784 Note: This function may, in multibyte locales, return non-NULL if STRING
785 is of smaller length than PREFIX!
786 Unlike strncasecmp(), this function works correctly in multibyte
788 _GL_EXTERN_C
char * mbspcasecmp (const char *string
, const char *prefix
)
789 _GL_ARG_NONNULL ((1, 2));
792 #if @GNULIB_MBSCASESTR@
793 /* Find the first occurrence of the character string NEEDLE in the character
794 string HAYSTACK, using case-insensitive comparison.
795 Note: This function may, in multibyte locales, return success even if
796 strlen (haystack) < strlen (needle) !
797 Unlike strcasestr(), this function works correctly in multibyte locales. */
798 _GL_EXTERN_C
char * mbscasestr (const char *haystack
, const char *needle
)
799 _GL_ARG_NONNULL ((1, 2));
803 /* Find the first occurrence in the character string STRING of any character
804 in the character string ACCEPT. Return the number of bytes from the
805 beginning of the string to this occurrence, or to the end of the string
807 Unlike strcspn(), this function works correctly in multibyte locales. */
808 _GL_EXTERN_C
size_t mbscspn (const char *string
, const char *accept
)
809 _GL_ARG_NONNULL ((1, 2));
813 /* Find the first occurrence in the character string STRING of any character
814 in the character string ACCEPT. Return the pointer to it, or NULL if none
816 Unlike strpbrk(), this function works correctly in multibyte locales. */
818 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
819 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
821 _GL_FUNCDECL_RPL (mbspbrk
, char *, (const char *string
, const char *accept
)
822 _GL_ARG_NONNULL ((1, 2)));
823 _GL_CXXALIAS_RPL (mbspbrk
, char *, (const char *string
, const char *accept
));
825 _GL_FUNCDECL_SYS (mbspbrk
, char *, (const char *string
, const char *accept
)
826 _GL_ARG_NONNULL ((1, 2)));
827 _GL_CXXALIAS_SYS (mbspbrk
, char *, (const char *string
, const char *accept
));
829 _GL_CXXALIASWARN (mbspbrk
);
833 /* Find the first occurrence in the character string STRING of any character
834 not in the character string REJECT. Return the number of bytes from the
835 beginning of the string to this occurrence, or to the end of the string
837 Unlike strspn(), this function works correctly in multibyte locales. */
838 _GL_EXTERN_C
size_t mbsspn (const char *string
, const char *reject
)
839 _GL_ARG_NONNULL ((1, 2));
843 /* Search the next delimiter (multibyte character listed in the character
844 string DELIM) starting at the character string *STRINGP.
845 If one is found, overwrite it with a NUL, and advance *STRINGP to point
846 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
847 If *STRINGP was already NULL, nothing happens.
848 Return the old value of *STRINGP.
850 This is a variant of mbstok_r() that supports empty fields.
852 Caveat: It modifies the original string.
853 Caveat: These functions cannot be used on constant strings.
854 Caveat: The identity of the delimiting character is lost.
856 See also mbstok_r(). */
857 _GL_EXTERN_C
char * mbssep (char **stringp
, const char *delim
)
858 _GL_ARG_NONNULL ((1, 2));
861 #if @GNULIB_MBSTOK_R@
862 /* Parse the character string STRING into tokens separated by characters in
863 the character string DELIM.
864 If STRING is NULL, the saved pointer in SAVE_PTR is used as
865 the next starting point. For example:
866 char s[] = "-abc-=-def";
868 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
869 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
870 x = mbstok_r(NULL, "=", &sp); // x = NULL
873 Caveat: It modifies the original string.
874 Caveat: These functions cannot be used on constant strings.
875 Caveat: The identity of the delimiting character is lost.
877 See also mbssep(). */
878 _GL_EXTERN_C
char * mbstok_r (char *string
, const char *delim
, char **save_ptr
)
879 _GL_ARG_NONNULL ((2, 3));
882 /* Map any int, typically from errno, into an error message. */
883 #if @GNULIB_STRERROR@
884 # if @REPLACE_STRERROR@
885 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
887 # define strerror rpl_strerror
889 _GL_FUNCDECL_RPL (strerror
, char *, (int));
890 _GL_CXXALIAS_RPL (strerror
, char *, (int));
892 _GL_CXXALIAS_SYS (strerror
, char *, (int));
894 _GL_CXXALIASWARN (strerror
);
895 #elif defined GNULIB_POSIXCHECK
897 /* Assume strerror is always declared. */
898 _GL_WARN_ON_USE (strerror
, "strerror is unportable - "
899 "use gnulib module strerror to guarantee non-NULL result");
902 /* Map any int, typically from errno, into an error message. Multithread-safe.
903 Uses the POSIX declaration, not the glibc declaration. */
904 #if @GNULIB_STRERROR_R@
905 # if @REPLACE_STRERROR_R@
906 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
908 # define strerror_r rpl_strerror_r
910 _GL_FUNCDECL_RPL (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
)
911 _GL_ARG_NONNULL ((2)));
912 _GL_CXXALIAS_RPL (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
));
914 # if !@HAVE_DECL_STRERROR_R@
915 _GL_FUNCDECL_SYS (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
)
916 _GL_ARG_NONNULL ((2)));
918 _GL_CXXALIAS_SYS (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
));
920 # if @HAVE_DECL_STRERROR_R@
921 _GL_CXXALIASWARN (strerror_r
);
923 #elif defined GNULIB_POSIXCHECK
925 # if HAVE_RAW_DECL_STRERROR_R
926 _GL_WARN_ON_USE (strerror_r
, "strerror_r is unportable - "
927 "use gnulib module strerror_r-posix for portability");
931 #if @GNULIB_STRSIGNAL@
932 # if @REPLACE_STRSIGNAL@
933 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
934 # define strsignal rpl_strsignal
936 _GL_FUNCDECL_RPL (strsignal
, char *, (int __sig
));
937 _GL_CXXALIAS_RPL (strsignal
, char *, (int __sig
));
939 # if ! @HAVE_DECL_STRSIGNAL@
940 _GL_FUNCDECL_SYS (strsignal
, char *, (int __sig
));
942 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
944 _GL_CXXALIAS_SYS_CAST (strsignal
, char *, (int __sig
));
946 _GL_CXXALIASWARN (strsignal
);
947 #elif defined GNULIB_POSIXCHECK
949 # if HAVE_RAW_DECL_STRSIGNAL
950 _GL_WARN_ON_USE (strsignal
, "strsignal is unportable - "
951 "use gnulib module strsignal for portability");
955 #if @GNULIB_STRVERSCMP@
956 # if !@HAVE_STRVERSCMP@
957 _GL_FUNCDECL_SYS (strverscmp
, int, (const char *, const char *)
958 _GL_ARG_NONNULL ((1, 2)));
960 _GL_CXXALIAS_SYS (strverscmp
, int, (const char *, const char *));
961 _GL_CXXALIASWARN (strverscmp
);
962 #elif defined GNULIB_POSIXCHECK
964 # if HAVE_RAW_DECL_STRVERSCMP
965 _GL_WARN_ON_USE (strverscmp
, "strverscmp is unportable - "
966 "use gnulib module strverscmp for portability");
971 #endif /* _GL_STRING_H */
972 #endif /* _GL_STRING_H */