1 /* A GNU-like <string.h>.
3 Copyright (C) 1995-1996, 2001-2025 Free Software Foundation, Inc.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 @PRAGMA_SYSTEM_HEADER@
23 #if defined _@GUARD_PREFIX@_ALREADY_INCLUDING_STRING_H
24 /* Special invocation convention:
25 - On OS X/NetBSD we have a sequence of nested includes
26 <string.h> -> <strings.h> -> "string.h"
27 In this situation system _chk variants due to -D_FORTIFY_SOURCE
28 might be used after any replacements defined here. */
30 #@INCLUDE_NEXT@ @NEXT_STRING_H@
33 /* Normal invocation convention. */
35 #ifndef _@GUARD_PREFIX@_STRING_H
37 #define _@GUARD_PREFIX@_ALREADY_INCLUDING_STRING_H
39 /* The include_next requires a split double-inclusion guard. */
40 #@INCLUDE_NEXT@ @NEXT_STRING_H@
42 #undef _@GUARD_PREFIX@_ALREADY_INCLUDING_STRING_H
44 #ifndef _@GUARD_PREFIX@_STRING_H
45 #define _@GUARD_PREFIX@_STRING_H
47 /* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC,
48 _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK,
50 #if !_GL_CONFIG_H_INCLUDED
51 #error "Please include config.h first."
54 /* NetBSD 5.0 mis-defines NULL. */
57 /* MirBSD defines mbslen as a macro. */
58 #if @GNULIB_MBSLEN@ && defined __MirBSD__
62 /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
63 /* But in any case avoid namespace pollution on glibc systems. */
64 #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
65 && ! defined __GLIBC__
69 /* AIX 7.2 and Android 13 declare ffsl and ffsll in <strings.h>, not in
71 /* But in any case avoid namespace pollution on glibc systems. */
72 #if ((@GNULIB_FFSL@ || @GNULIB_FFSLL@ || defined GNULIB_POSIXCHECK) \
73 && (defined _AIX || defined __ANDROID__)) \
74 && ! defined __GLIBC__
78 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
79 that can be freed by passing them as the Ith argument to the
81 #ifndef _GL_ATTRIBUTE_DEALLOC
82 # if __GNUC__ >= 11 && !defined __clang__
83 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
85 # define _GL_ATTRIBUTE_DEALLOC(f, i)
89 /* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
90 can be freed via 'free'; it can be used only after declaring 'free'. */
91 /* Applies to: functions. Cannot be used on inline functions. */
92 #ifndef _GL_ATTRIBUTE_DEALLOC_FREE
93 # if defined __cplusplus && defined __GNUC__ && !defined __clang__
94 /* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
95 # define _GL_ATTRIBUTE_DEALLOC_FREE \
96 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
98 # define _GL_ATTRIBUTE_DEALLOC_FREE \
99 _GL_ATTRIBUTE_DEALLOC (free, 1)
103 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
105 /* Applies to: functions. */
106 #ifndef _GL_ATTRIBUTE_MALLOC
107 # if __GNUC__ >= 3 || defined __clang__
108 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
110 # define _GL_ATTRIBUTE_MALLOC
114 /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
116 #ifndef _GL_ATTRIBUTE_NOTHROW
117 # if defined __cplusplus
118 # if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major__ >= 4
119 # if __cplusplus >= 201103L
120 # define _GL_ATTRIBUTE_NOTHROW noexcept (true)
122 # define _GL_ATTRIBUTE_NOTHROW throw ()
125 # define _GL_ATTRIBUTE_NOTHROW
128 # if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__
129 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
131 # define _GL_ATTRIBUTE_NOTHROW
136 /* The __attribute__ feature is available in gcc versions 2.5 and later.
137 The attribute __pure__ was added in gcc 2.96. */
138 #ifndef _GL_ATTRIBUTE_PURE
139 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
140 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
142 # define _GL_ATTRIBUTE_PURE /* empty */
146 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
148 /* The definition of _GL_ARG_NONNULL is copied here. */
150 /* The definition of _GL_WARN_ON_USE is copied here. */
152 /* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though <stdlib.h> may not have
153 been included yet. */
154 #if @GNULIB_FREE_POSIX@
155 # if (@REPLACE_FREE@ && !defined free \
156 && !(defined __cplusplus && defined GNULIB_NAMESPACE))
157 /* We can't do '#define free rpl_free' here. */
158 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
159 _GL_EXTERN_C
void rpl_free (void *) _GL_ATTRIBUTE_NOTHROW
;
161 _GL_EXTERN_C
void rpl_free (void *);
163 # undef _GL_ATTRIBUTE_DEALLOC_FREE
164 # define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
166 # if defined _MSC_VER && !defined free
169 __declspec (dllimport
)
171 void __cdecl
free (void *);
173 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
174 _GL_EXTERN_C
void free (void *) _GL_ATTRIBUTE_NOTHROW
;
176 _GL_EXTERN_C
void free (void *);
181 # if defined _MSC_VER && !defined free
184 __declspec (dllimport
)
186 void __cdecl
free (void *);
188 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
189 _GL_EXTERN_C
void free (void *) _GL_ATTRIBUTE_NOTHROW
;
191 _GL_EXTERN_C
void free (void *);
196 /* Clear a block of memory. The compiler will not delete a call to
197 this function, even if the block is dead after the call. */
198 #if @GNULIB_EXPLICIT_BZERO@
199 # if ! @HAVE_EXPLICIT_BZERO@
200 _GL_FUNCDECL_SYS (explicit_bzero
, void,
201 (void *__dest
, size_t __n
), _GL_ARG_NONNULL ((1)));
203 _GL_CXXALIAS_SYS (explicit_bzero
, void, (void *__dest
, size_t __n
));
204 _GL_CXXALIASWARN (explicit_bzero
);
205 #elif defined GNULIB_POSIXCHECK
206 # undef explicit_bzero
207 # if HAVE_RAW_DECL_EXPLICIT_BZERO
208 _GL_WARN_ON_USE (explicit_bzero
, "explicit_bzero is unportable - "
209 "use gnulib module explicit_bzero for portability");
213 /* Find the index of the least-significant set bit. */
216 _GL_FUNCDECL_SYS (ffsl
, int, (long int i
), );
218 _GL_CXXALIAS_SYS (ffsl
, int, (long int i
));
219 _GL_CXXALIASWARN (ffsl
);
220 #elif defined GNULIB_POSIXCHECK
222 # if HAVE_RAW_DECL_FFSL
223 _GL_WARN_ON_USE (ffsl
, "ffsl is not portable - use the ffsl module");
228 /* Find the index of the least-significant set bit. */
231 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
232 # define ffsll rpl_ffsll
234 _GL_FUNCDECL_RPL (ffsll
, int, (long long int i
), );
235 _GL_CXXALIAS_RPL (ffsll
, int, (long long int i
));
238 _GL_FUNCDECL_SYS (ffsll
, int, (long long int i
), );
240 _GL_CXXALIAS_SYS (ffsll
, int, (long long int i
));
242 _GL_CXXALIASWARN (ffsll
);
243 #elif defined GNULIB_POSIXCHECK
245 # if HAVE_RAW_DECL_FFSLL
246 _GL_WARN_ON_USE (ffsll
, "ffsll is not portable - use the ffsll module");
251 #if @GNULIB_MDA_MEMCCPY@
252 /* On native Windows, map 'memccpy' to '_memccpy', so that -loldnames is not
253 required. In C++ with GNULIB_NAMESPACE, avoid differences between
254 platforms by defining GNULIB_NAMESPACE::memccpy always. */
255 # if defined _WIN32 && !defined __CYGWIN__
256 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
258 # define memccpy _memccpy
260 _GL_CXXALIAS_MDA (memccpy
, void *,
261 (void *dest
, const void *src
, int c
, size_t n
));
263 _GL_CXXALIAS_SYS (memccpy
, void *,
264 (void *dest
, const void *src
, int c
, size_t n
));
266 _GL_CXXALIASWARN (memccpy
);
270 /* Return the first instance of C within N bytes of S, or NULL. */
272 # if @REPLACE_MEMCHR@
273 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
275 # define memchr rpl_memchr
277 _GL_FUNCDECL_RPL (memchr
, void *, (void const *__s
, int __c
, size_t __n
),
279 _GL_ARG_NONNULL ((1)));
280 _GL_CXXALIAS_RPL (memchr
, void *, (void const *__s
, int __c
, size_t __n
));
282 /* On some systems, this function is defined as an overloaded function:
283 extern "C" { const void * std::memchr (const void *, int, size_t); }
284 extern "C++" { void * std::memchr (void *, int, size_t); } */
285 _GL_CXXALIAS_SYS_CAST2 (memchr
,
286 void *, (void const *__s
, int __c
, size_t __n
),
287 void const *, (void const *__s
, int __c
, size_t __n
));
289 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
290 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
291 || defined __clang__)
292 _GL_CXXALIASWARN1 (memchr
, void *,
293 (void *__s
, int __c
, size_t __n
)
294 _GL_ATTRIBUTE_NOTHROW
);
295 _GL_CXXALIASWARN1 (memchr
, void const *,
296 (void const *__s
, int __c
, size_t __n
)
297 _GL_ATTRIBUTE_NOTHROW
);
298 # elif __GLIBC__ >= 2
299 _GL_CXXALIASWARN (memchr
);
301 #elif defined GNULIB_POSIXCHECK
303 /* Assume memchr is always declared. */
304 _GL_WARN_ON_USE (memchr
, "memchr has platform-specific bugs - "
305 "use gnulib module memchr for portability" );
308 /* Return the first occurrence of NEEDLE in HAYSTACK. */
310 # if @REPLACE_MEMMEM@
311 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
312 # define memmem rpl_memmem
314 _GL_FUNCDECL_RPL (memmem
, void *,
315 (void const *__haystack
, size_t __haystack_len
,
316 void const *__needle
, size_t __needle_len
),
318 _GL_ARG_NONNULL ((1, 3)));
319 _GL_CXXALIAS_RPL (memmem
, void *,
320 (void const *__haystack
, size_t __haystack_len
,
321 void const *__needle
, size_t __needle_len
));
323 # if ! @HAVE_DECL_MEMMEM@
324 _GL_FUNCDECL_SYS (memmem
, void *,
325 (void const *__haystack
, size_t __haystack_len
,
326 void const *__needle
, size_t __needle_len
),
328 _GL_ARG_NONNULL ((1, 3)));
330 _GL_CXXALIAS_SYS (memmem
, void *,
331 (void const *__haystack
, size_t __haystack_len
,
332 void const *__needle
, size_t __needle_len
));
334 _GL_CXXALIASWARN (memmem
);
335 #elif defined GNULIB_POSIXCHECK
337 # if HAVE_RAW_DECL_MEMMEM
338 _GL_WARN_ON_USE (memmem
, "memmem is unportable and often quadratic - "
339 "use gnulib module memmem-simple for portability, "
340 "and module memmem for speed" );
344 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
345 last written byte. */
347 # if @REPLACE_MEMPCPY@
348 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
350 # define mempcpy rpl_mempcpy
352 _GL_FUNCDECL_RPL (mempcpy
, void *,
353 (void *restrict __dest
, void const *restrict __src
,
355 _GL_ARG_NONNULL ((1, 2)));
356 _GL_CXXALIAS_RPL (mempcpy
, void *,
357 (void *restrict __dest
, void const *restrict __src
,
361 _GL_FUNCDECL_SYS (mempcpy
, void *,
362 (void *restrict __dest
, void const *restrict __src
,
364 _GL_ARG_NONNULL ((1, 2)));
366 _GL_CXXALIAS_SYS (mempcpy
, void *,
367 (void *restrict __dest
, void const *restrict __src
,
371 _GL_CXXALIASWARN (mempcpy
);
373 #elif defined GNULIB_POSIXCHECK
375 # if HAVE_RAW_DECL_MEMPCPY
376 _GL_WARN_ON_USE (mempcpy
, "mempcpy is unportable - "
377 "use gnulib module mempcpy for portability");
381 /* Search backwards through a block for a byte (specified as an int). */
383 # if ! @HAVE_DECL_MEMRCHR@
384 _GL_FUNCDECL_SYS (memrchr
, void *, (void const *, int, size_t),
386 _GL_ARG_NONNULL ((1)));
388 /* On some systems, this function is defined as an overloaded function:
389 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
390 extern "C++" { void * std::memrchr (void *, int, size_t); } */
391 _GL_CXXALIAS_SYS_CAST2 (memrchr
,
392 void *, (void const *, int, size_t),
393 void const *, (void const *, int, size_t));
394 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
395 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
396 || defined __clang__)
397 _GL_CXXALIASWARN1 (memrchr
, void *,
398 (void *, int, size_t)
399 _GL_ATTRIBUTE_NOTHROW
);
400 _GL_CXXALIASWARN1 (memrchr
, void const *,
401 (void const *, int, size_t)
402 _GL_ATTRIBUTE_NOTHROW
);
403 # elif __GLIBC__ >= 2
404 _GL_CXXALIASWARN (memrchr
);
406 #elif defined GNULIB_POSIXCHECK
408 # if HAVE_RAW_DECL_MEMRCHR
409 _GL_WARN_ON_USE (memrchr
, "memrchr is unportable - "
410 "use gnulib module memrchr for portability");
414 /* Overwrite a block of memory. The compiler will not optimize
415 effects away, even if the block is dead after the call. */
416 #if @GNULIB_MEMSET_EXPLICIT@
417 # if @REPLACE_MEMSET_EXPLICIT@
418 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
419 # undef memset_explicit
420 # define memset_explicit rpl_memset_explicit
422 _GL_FUNCDECL_RPL (memset_explicit
, void *,
423 (void *__dest
, int __c
, size_t __n
), _GL_ARG_NONNULL ((1)));
424 _GL_CXXALIAS_RPL (memset_explicit
, void *, (void *__dest
, int __c
, size_t __n
));
426 # if !@HAVE_MEMSET_EXPLICIT@
427 _GL_FUNCDECL_SYS (memset_explicit
, void *,
428 (void *__dest
, int __c
, size_t __n
), _GL_ARG_NONNULL ((1)));
430 _GL_CXXALIAS_SYS (memset_explicit
, void *, (void *__dest
, int __c
, size_t __n
));
432 _GL_CXXALIASWARN (memset_explicit
);
433 #elif defined GNULIB_POSIXCHECK
434 # undef memset_explicit
435 # if HAVE_RAW_DECL_MEMSET_EXPLICIT
436 _GL_WARN_ON_USE (memset_explicit
, "memset_explicit is unportable - "
437 "use gnulib module memset_explicit for portability");
441 /* Find the first occurrence of C in S. More efficient than
442 memchr(S,C,N), at the expense of undefined behavior if C does not
443 occur within N bytes. */
444 #if @GNULIB_RAWMEMCHR@
445 # if ! @HAVE_RAWMEMCHR@
446 _GL_FUNCDECL_SYS (rawmemchr
, void *, (void const *__s
, int __c_in
),
448 _GL_ARG_NONNULL ((1)));
450 /* On some systems, this function is defined as an overloaded function:
451 extern "C++" { const void * std::rawmemchr (const void *, int); }
452 extern "C++" { void * std::rawmemchr (void *, int); } */
453 _GL_CXXALIAS_SYS_CAST2 (rawmemchr
,
454 void *, (void const *__s
, int __c_in
),
455 void const *, (void const *__s
, int __c_in
));
456 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
457 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
458 || defined __clang__)
459 _GL_CXXALIASWARN1 (rawmemchr
, void *,
460 (void *__s
, int __c_in
)
461 _GL_ATTRIBUTE_NOTHROW
);
462 _GL_CXXALIASWARN1 (rawmemchr
, void const *,
463 (void const *__s
, int __c_in
)
464 _GL_ATTRIBUTE_NOTHROW
);
466 _GL_CXXALIASWARN (rawmemchr
);
468 #elif defined GNULIB_POSIXCHECK
470 # if HAVE_RAW_DECL_RAWMEMCHR
471 _GL_WARN_ON_USE (rawmemchr
, "rawmemchr is unportable - "
472 "use gnulib module rawmemchr for portability");
476 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
478 # if @REPLACE_STPCPY@
479 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
481 # define stpcpy rpl_stpcpy
483 _GL_FUNCDECL_RPL (stpcpy
, char *,
484 (char *restrict __dst
, char const *restrict __src
),
485 _GL_ARG_NONNULL ((1, 2)));
486 _GL_CXXALIAS_RPL (stpcpy
, char *,
487 (char *restrict __dst
, char const *restrict __src
));
490 _GL_FUNCDECL_SYS (stpcpy
, char *,
491 (char *restrict __dst
, char const *restrict __src
),
492 _GL_ARG_NONNULL ((1, 2)));
494 _GL_CXXALIAS_SYS (stpcpy
, char *,
495 (char *restrict __dst
, char const *restrict __src
));
498 _GL_CXXALIASWARN (stpcpy
);
500 #elif defined GNULIB_POSIXCHECK
502 # if HAVE_RAW_DECL_STPCPY
503 _GL_WARN_ON_USE (stpcpy
, "stpcpy is unportable - "
504 "use gnulib module stpcpy for portability");
508 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
509 last non-NUL byte written into DST. */
511 # if @REPLACE_STPNCPY@
512 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
514 # define stpncpy rpl_stpncpy
516 _GL_FUNCDECL_RPL (stpncpy
, char *,
517 (char *restrict __dst
, char const *restrict __src
,
519 _GL_ARG_NONNULL ((1, 2)));
520 _GL_CXXALIAS_RPL (stpncpy
, char *,
521 (char *restrict __dst
, char const *restrict __src
,
524 # if ! @HAVE_STPNCPY@
525 _GL_FUNCDECL_SYS (stpncpy
, char *,
526 (char *restrict __dst
, char const *restrict __src
,
528 _GL_ARG_NONNULL ((1, 2)));
530 _GL_CXXALIAS_SYS (stpncpy
, char *,
531 (char *restrict __dst
, char const *restrict __src
,
535 _GL_CXXALIASWARN (stpncpy
);
537 #elif defined GNULIB_POSIXCHECK
539 # if HAVE_RAW_DECL_STPNCPY
540 _GL_WARN_ON_USE (stpncpy
, "stpncpy is unportable - "
541 "use gnulib module stpncpy for portability");
545 #if defined GNULIB_POSIXCHECK
546 /* strchr() does not work with multibyte strings if the locale encoding is
547 GB18030 and the character to be searched is a digit. */
549 /* Assume strchr is always declared. */
550 _GL_WARN_ON_USE_CXX (strchr
,
551 const char *, char *, (const char *, int),
552 "strchr cannot work correctly on character strings "
553 "in some multibyte locales - "
554 "use mbschr if you care about internationalization");
557 /* Find the first occurrence of C in S or the final NUL byte. */
558 #if @GNULIB_STRCHRNUL@
559 # if @REPLACE_STRCHRNUL@
560 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
561 # define strchrnul rpl_strchrnul
563 _GL_FUNCDECL_RPL (strchrnul
, char *, (const char *__s
, int __c_in
),
565 _GL_ARG_NONNULL ((1)));
566 _GL_CXXALIAS_RPL (strchrnul
, char *,
567 (const char *str
, int ch
));
569 # if ! @HAVE_STRCHRNUL@
570 _GL_FUNCDECL_SYS (strchrnul
, char *, (char const *__s
, int __c_in
),
572 _GL_ARG_NONNULL ((1)));
574 /* On some systems, this function is defined as an overloaded function:
575 extern "C++" { const char * std::strchrnul (const char *, int); }
576 extern "C++" { char * std::strchrnul (char *, int); } */
577 _GL_CXXALIAS_SYS_CAST2 (strchrnul
,
578 char *, (char const *__s
, int __c_in
),
579 char const *, (char const *__s
, int __c_in
));
581 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
582 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
583 || defined __clang__)
584 _GL_CXXALIASWARN1 (strchrnul
, char *,
585 (char *__s
, int __c_in
)
586 _GL_ATTRIBUTE_NOTHROW
);
587 _GL_CXXALIASWARN1 (strchrnul
, char const *,
588 (char const *__s
, int __c_in
)
589 _GL_ATTRIBUTE_NOTHROW
);
590 # elif __GLIBC__ >= 2
591 _GL_CXXALIASWARN (strchrnul
);
593 #elif defined GNULIB_POSIXCHECK
595 # if HAVE_RAW_DECL_STRCHRNUL
596 _GL_WARN_ON_USE (strchrnul
, "strchrnul is unportable - "
597 "use gnulib module strchrnul for portability");
601 /* Duplicate S, returning an identical malloc'd string. */
603 # if @REPLACE_STRDUP@
604 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
606 # define strdup rpl_strdup
608 _GL_FUNCDECL_RPL (strdup
, char *,
610 _GL_ARG_NONNULL ((1))
611 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
612 _GL_CXXALIAS_RPL (strdup
, char *, (char const *__s
));
613 # elif defined _WIN32 && !defined __CYGWIN__
614 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
616 # define strdup _strdup
618 _GL_CXXALIAS_MDA (strdup
, char *, (char const *__s
));
620 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
621 /* strdup exists as a function and as a macro. Get rid of the macro. */
624 # if (!@HAVE_DECL_STRDUP@ || (__GNUC__ >= 11 && !defined __clang__)) \
626 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
627 _GL_FUNCDECL_SYS (strdup
, char *,
629 _GL_ARG_NONNULL ((1))
630 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
)
631 _GL_ATTRIBUTE_NOTHROW
;
633 _GL_FUNCDECL_SYS (strdup
, char *,
635 _GL_ARG_NONNULL ((1))
636 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
639 _GL_CXXALIAS_SYS (strdup
, char *, (char const *__s
));
641 _GL_CXXALIASWARN (strdup
);
643 # if (__GNUC__ >= 11 && !defined __clang__) && !defined strdup
644 /* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */
645 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
646 _GL_FUNCDECL_SYS (strdup
, char *,
648 _GL_ARG_NONNULL ((1))
649 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
)
650 _GL_ATTRIBUTE_NOTHROW
;
652 _GL_FUNCDECL_SYS (strdup
, char *,
654 _GL_ARG_NONNULL ((1))
655 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
658 # if defined GNULIB_POSIXCHECK
660 # if HAVE_RAW_DECL_STRDUP
661 _GL_WARN_ON_USE (strdup
, "strdup is unportable - "
662 "use gnulib module strdup for portability");
664 # elif @GNULIB_MDA_STRDUP@
665 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
666 required. In C++ with GNULIB_NAMESPACE, avoid differences between
667 platforms by defining GNULIB_NAMESPACE::strdup always. */
668 # if defined _WIN32 && !defined __CYGWIN__
669 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
671 # define strdup _strdup
673 _GL_CXXALIAS_MDA (strdup
, char *, (char const *__s
));
675 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
678 _GL_CXXALIAS_SYS (strdup
, char *, (char const *__s
));
680 _GL_CXXALIASWARN (strdup
);
684 /* Append no more than N characters from SRC onto DEST. */
686 # if @REPLACE_STRNCAT@
687 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
689 # define strncat rpl_strncat
691 _GL_FUNCDECL_RPL (strncat
, char *,
692 (char *restrict dest
, const char *restrict src
, size_t n
),
693 _GL_ARG_NONNULL ((1, 2)));
694 _GL_CXXALIAS_RPL (strncat
, char *,
695 (char *restrict dest
, const char *restrict src
, size_t n
));
697 _GL_CXXALIAS_SYS (strncat
, char *,
698 (char *restrict dest
, const char *restrict src
, size_t n
));
701 _GL_CXXALIASWARN (strncat
);
703 #elif defined GNULIB_POSIXCHECK
705 # if HAVE_RAW_DECL_STRNCAT
706 _GL_WARN_ON_USE (strncat
, "strncat is unportable - "
707 "use gnulib module strncat for portability");
711 /* Return a newly allocated copy of at most N bytes of STRING. */
713 # if @REPLACE_STRNDUP@
714 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
716 # define strndup rpl_strndup
718 _GL_FUNCDECL_RPL (strndup
, char *,
719 (char const *__s
, size_t __n
),
720 _GL_ARG_NONNULL ((1))
721 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
722 _GL_CXXALIAS_RPL (strndup
, char *, (char const *__s
, size_t __n
));
724 # if !@HAVE_DECL_STRNDUP@ \
725 || ((__GNUC__ >= 11 && !defined __clang__) && !defined strndup)
726 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
727 _GL_FUNCDECL_SYS (strndup
, char *,
728 (char const *__s
, size_t __n
),
729 _GL_ARG_NONNULL ((1))
730 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
)
731 _GL_ATTRIBUTE_NOTHROW
;
733 _GL_FUNCDECL_SYS (strndup
, char *,
734 (char const *__s
, size_t __n
),
735 _GL_ARG_NONNULL ((1))
736 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
739 _GL_CXXALIAS_SYS (strndup
, char *, (char const *__s
, size_t __n
));
741 _GL_CXXALIASWARN (strndup
);
743 # if (__GNUC__ >= 11 && !defined __clang__) && !defined strndup
744 /* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */
745 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
746 _GL_FUNCDECL_SYS (strndup
, char *,
747 (char const *__s
, size_t __n
),
748 _GL_ARG_NONNULL ((1))
749 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
)
750 _GL_ATTRIBUTE_NOTHROW
;
752 _GL_FUNCDECL_SYS (strndup
, char *,
753 (char const *__s
, size_t __n
),
754 _GL_ARG_NONNULL ((1))
755 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
758 # if defined GNULIB_POSIXCHECK
760 # if HAVE_RAW_DECL_STRNDUP
761 _GL_WARN_ON_USE (strndup
, "strndup is unportable - "
762 "use gnulib module strndup for portability");
767 /* Find the length (number of bytes) of STRING, but scan at most
768 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
771 # if @REPLACE_STRNLEN@
772 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
774 # define strnlen rpl_strnlen
776 _GL_FUNCDECL_RPL (strnlen
, size_t, (char const *__s
, size_t __maxlen
),
778 _GL_ARG_NONNULL ((1)));
779 _GL_CXXALIAS_RPL (strnlen
, size_t, (char const *__s
, size_t __maxlen
));
781 # if ! @HAVE_DECL_STRNLEN@
782 _GL_FUNCDECL_SYS (strnlen
, size_t, (char const *__s
, size_t __maxlen
),
784 _GL_ARG_NONNULL ((1)));
786 _GL_CXXALIAS_SYS (strnlen
, size_t, (char const *__s
, size_t __maxlen
));
788 _GL_CXXALIASWARN (strnlen
);
789 #elif defined GNULIB_POSIXCHECK
791 # if HAVE_RAW_DECL_STRNLEN
792 _GL_WARN_ON_USE (strnlen
, "strnlen is unportable - "
793 "use gnulib module strnlen for portability");
797 #if defined GNULIB_POSIXCHECK
798 /* strcspn() assumes the second argument is a list of single-byte characters.
799 Even in this simple case, it does not work with multibyte strings if the
800 locale encoding is GB18030 and one of the characters to be searched is a
803 /* Assume strcspn is always declared. */
804 _GL_WARN_ON_USE (strcspn
, "strcspn cannot work correctly on character strings "
805 "in multibyte locales - "
806 "use mbscspn if you care about internationalization");
809 /* Find the first occurrence in S of any character in ACCEPT. */
811 # if ! @HAVE_STRPBRK@
812 _GL_FUNCDECL_SYS (strpbrk
, char *, (char const *__s
, char const *__accept
),
814 _GL_ARG_NONNULL ((1, 2)));
816 /* On some systems, this function is defined as an overloaded function:
817 extern "C" { const char * strpbrk (const char *, const char *); }
818 extern "C++" { char * strpbrk (char *, const char *); } */
819 _GL_CXXALIAS_SYS_CAST2 (strpbrk
,
820 char *, (char const *__s
, char const *__accept
),
821 const char *, (char const *__s
, char const *__accept
));
822 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
823 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
824 || defined __clang__)
825 _GL_CXXALIASWARN1 (strpbrk
, char *,
826 (char *__s
, char const *__accept
)
827 _GL_ATTRIBUTE_NOTHROW
);
828 _GL_CXXALIASWARN1 (strpbrk
, char const *,
829 (char const *__s
, char const *__accept
)
830 _GL_ATTRIBUTE_NOTHROW
);
831 # elif __GLIBC__ >= 2
832 _GL_CXXALIASWARN (strpbrk
);
834 # if defined GNULIB_POSIXCHECK
835 /* strpbrk() assumes the second argument is a list of single-byte characters.
836 Even in this simple case, it does not work with multibyte strings if the
837 locale encoding is GB18030 and one of the characters to be searched is a
840 _GL_WARN_ON_USE_CXX (strpbrk
,
841 const char *, char *, (const char *, const char *),
842 "strpbrk cannot work correctly on character strings "
843 "in multibyte locales - "
844 "use mbspbrk if you care about internationalization");
846 #elif defined GNULIB_POSIXCHECK
848 # if HAVE_RAW_DECL_STRPBRK
849 _GL_WARN_ON_USE_CXX (strpbrk
,
850 const char *, char *, (const char *, const char *),
851 "strpbrk is unportable - "
852 "use gnulib module strpbrk for portability");
856 #if defined GNULIB_POSIXCHECK
857 /* strspn() assumes the second argument is a list of single-byte characters.
858 Even in this simple case, it cannot work with multibyte strings. */
860 /* Assume strspn is always declared. */
861 _GL_WARN_ON_USE (strspn
, "strspn cannot work correctly on character strings "
862 "in multibyte locales - "
863 "use mbsspn if you care about internationalization");
866 #if defined GNULIB_POSIXCHECK
867 /* strrchr() does not work with multibyte strings if the locale encoding is
868 GB18030 and the character to be searched is a digit. */
870 /* Assume strrchr is always declared. */
871 _GL_WARN_ON_USE_CXX (strrchr
,
872 const char *, char *, (const char *, int),
873 "strrchr cannot work correctly on character strings "
874 "in some multibyte locales - "
875 "use mbsrchr if you care about internationalization");
878 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
879 If one is found, overwrite it with a NUL, and advance *STRINGP
880 to point to the next char after it. Otherwise, set *STRINGP to NULL.
881 If *STRINGP was already NULL, nothing happens.
882 Return the old value of *STRINGP.
884 This is a variant of strtok() that is multithread-safe and supports
887 Caveat: It modifies the original string.
888 Caveat: These functions cannot be used on constant strings.
889 Caveat: The identity of the delimiting character is lost.
890 Caveat: It doesn't work with multibyte strings unless all of the delimiter
891 characters are ASCII characters < 0x30.
893 See also strtok_r(). */
896 _GL_FUNCDECL_SYS (strsep
, char *,
897 (char **restrict __stringp
, char const *restrict __delim
),
898 _GL_ARG_NONNULL ((1, 2)));
900 _GL_CXXALIAS_SYS (strsep
, char *,
901 (char **restrict __stringp
, char const *restrict __delim
));
902 _GL_CXXALIASWARN (strsep
);
903 # if defined GNULIB_POSIXCHECK
905 _GL_WARN_ON_USE (strsep
, "strsep cannot work correctly on character strings "
906 "in multibyte locales - "
907 "use mbssep if you care about internationalization");
909 #elif defined GNULIB_POSIXCHECK
911 # if HAVE_RAW_DECL_STRSEP
912 _GL_WARN_ON_USE (strsep
, "strsep is unportable - "
913 "use gnulib module strsep for portability");
918 # if @REPLACE_STRSTR@
919 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
920 # define strstr rpl_strstr
922 _GL_FUNCDECL_RPL (strstr
, char *, (const char *haystack
, const char *needle
),
924 _GL_ARG_NONNULL ((1, 2)));
925 _GL_CXXALIAS_RPL (strstr
, char *, (const char *haystack
, const char *needle
));
927 /* On some systems, this function is defined as an overloaded function:
928 extern "C++" { const char * strstr (const char *, const char *); }
929 extern "C++" { char * strstr (char *, const char *); } */
930 _GL_CXXALIAS_SYS_CAST2 (strstr
,
931 char *, (const char *haystack
, const char *needle
),
932 const char *, (const char *haystack
, const char *needle
));
934 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
935 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
936 || defined __clang__)
937 _GL_CXXALIASWARN1 (strstr
, char *,
938 (char *haystack
, const char *needle
)
939 _GL_ATTRIBUTE_NOTHROW
);
940 _GL_CXXALIASWARN1 (strstr
, const char *,
941 (const char *haystack
, const char *needle
)
942 _GL_ATTRIBUTE_NOTHROW
);
943 # elif __GLIBC__ >= 2
944 _GL_CXXALIASWARN (strstr
);
946 #elif defined GNULIB_POSIXCHECK
947 /* strstr() does not work with multibyte strings if the locale encoding is
948 different from UTF-8:
949 POSIX says that it operates on "strings", and "string" in POSIX is defined
950 as a sequence of bytes, not of characters. */
952 /* Assume strstr is always declared. */
953 _GL_WARN_ON_USE (strstr
, "strstr is quadratic on many systems, and cannot "
954 "work correctly on character strings in most "
955 "multibyte locales - "
956 "use mbsstr if you care about internationalization, "
957 "or use strstr if you care about speed");
960 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
962 #if @GNULIB_STRCASESTR@
963 # if @REPLACE_STRCASESTR@
964 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
965 # define strcasestr rpl_strcasestr
967 _GL_FUNCDECL_RPL (strcasestr
, char *,
968 (const char *haystack
, const char *needle
),
970 _GL_ARG_NONNULL ((1, 2)));
971 _GL_CXXALIAS_RPL (strcasestr
, char *,
972 (const char *haystack
, const char *needle
));
974 # if ! @HAVE_STRCASESTR@
975 _GL_FUNCDECL_SYS (strcasestr
, char *,
976 (const char *haystack
, const char *needle
),
978 _GL_ARG_NONNULL ((1, 2)));
980 /* On some systems, this function is defined as an overloaded function:
981 extern "C++" { const char * strcasestr (const char *, const char *); }
982 extern "C++" { char * strcasestr (char *, const char *); } */
983 _GL_CXXALIAS_SYS_CAST2 (strcasestr
,
984 char *, (const char *haystack
, const char *needle
),
985 const char *, (const char *haystack
, const char *needle
));
987 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
988 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
989 || defined __clang__)
990 _GL_CXXALIASWARN1 (strcasestr
, char *,
991 (char *haystack
, const char *needle
)
992 _GL_ATTRIBUTE_NOTHROW
);
993 _GL_CXXALIASWARN1 (strcasestr
, const char *,
994 (const char *haystack
, const char *needle
)
995 _GL_ATTRIBUTE_NOTHROW
);
996 # elif __GLIBC__ >= 2
997 _GL_CXXALIASWARN (strcasestr
);
999 #elif defined GNULIB_POSIXCHECK
1000 /* strcasestr() does not work with multibyte strings:
1001 It is a glibc extension, and glibc implements it only for unibyte
1004 # if HAVE_RAW_DECL_STRCASESTR
1005 _GL_WARN_ON_USE (strcasestr
, "strcasestr does work correctly on character "
1006 "strings in multibyte locales - "
1007 "use mbscasestr if you care about "
1008 "internationalization, or use c-strcasestr if you want "
1009 "a locale independent function");
1013 /* Parse S into tokens separated by characters in DELIM.
1014 If S is NULL, the saved pointer in SAVE_PTR is used as
1015 the next starting point. For example:
1016 char s[] = "-abc-=-def";
1018 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1019 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1020 x = strtok_r(NULL, "=", &sp); // x = NULL
1021 // s = "abc\0-def\0"
1023 This is a variant of strtok() that is multithread-safe.
1025 For the POSIX documentation for this function, see:
1026 https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html
1028 Caveat: It modifies the original string.
1029 Caveat: These functions cannot be used on constant strings.
1030 Caveat: The identity of the delimiting character is lost.
1031 Caveat: It doesn't work with multibyte strings unless all of the delimiter
1032 characters are ASCII characters < 0x30.
1034 See also strsep(). */
1035 #if @GNULIB_STRTOK_R@
1036 # if @REPLACE_STRTOK_R@
1037 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1039 # define strtok_r rpl_strtok_r
1041 _GL_FUNCDECL_RPL (strtok_r
, char *,
1042 (char *restrict s
, char const *restrict delim
,
1043 char **restrict save_ptr
),
1044 _GL_ARG_NONNULL ((2, 3)));
1045 _GL_CXXALIAS_RPL (strtok_r
, char *,
1046 (char *restrict s
, char const *restrict delim
,
1047 char **restrict save_ptr
));
1049 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
1052 # if ! @HAVE_DECL_STRTOK_R@
1053 _GL_FUNCDECL_SYS (strtok_r
, char *,
1054 (char *restrict s
, char const *restrict delim
,
1055 char **restrict save_ptr
),
1056 _GL_ARG_NONNULL ((2, 3)));
1058 _GL_CXXALIAS_SYS (strtok_r
, char *,
1059 (char *restrict s
, char const *restrict delim
,
1060 char **restrict save_ptr
));
1062 _GL_CXXALIASWARN (strtok_r
);
1063 # if defined GNULIB_POSIXCHECK
1064 _GL_WARN_ON_USE (strtok_r
, "strtok_r cannot work correctly on character "
1065 "strings in multibyte locales - "
1066 "use mbstok_r if you care about internationalization");
1068 #elif defined GNULIB_POSIXCHECK
1070 # if HAVE_RAW_DECL_STRTOK_R
1071 _GL_WARN_ON_USE (strtok_r
, "strtok_r is unportable - "
1072 "use gnulib module strtok_r for portability");
1077 /* The following functions are not specified by POSIX. They are gnulib
1080 #if @GNULIB_STR_STARTSWITH@
1081 /* Returns true if STRING starts with PREFIX.
1082 Returns false otherwise. */
1083 _GL_EXTERN_C
bool str_startswith (const char *string
, const char *prefix
)
1085 _GL_ARG_NONNULL ((1, 2));
1088 #if @GNULIB_STR_ENDSWITH@
1089 /* Returns true if STRING ends with SUFFIX.
1090 Returns false otherwise. */
1091 _GL_EXTERN_C
bool str_endswith (const char *string
, const char *prefix
)
1093 _GL_ARG_NONNULL ((1, 2));
1097 /* Return the number of multibyte characters in the character string STRING.
1098 This considers multibyte characters, unlike strlen, which counts bytes. */
1099 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
1102 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
1103 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1104 # define mbslen rpl_mbslen
1106 _GL_FUNCDECL_RPL (mbslen
, size_t, (const char *string
),
1108 _GL_ARG_NONNULL ((1)));
1109 _GL_CXXALIAS_RPL (mbslen
, size_t, (const char *string
));
1111 _GL_FUNCDECL_SYS (mbslen
, size_t, (const char *string
),
1113 _GL_ARG_NONNULL ((1)));
1114 _GL_CXXALIAS_SYS (mbslen
, size_t, (const char *string
));
1117 _GL_CXXALIASWARN (mbslen
);
1121 #if @GNULIB_MBSNLEN@
1122 /* Return the number of multibyte characters in the character string starting
1123 at STRING and ending at STRING + LEN. */
1124 _GL_EXTERN_C
size_t mbsnlen (const char *string
, size_t len
)
1126 _GL_ARG_NONNULL ((1));
1130 /* Locate the first single-byte character C in the character string STRING,
1131 and return a pointer to it. Return NULL if C is not found in STRING.
1132 Unlike strchr(), this function works correctly in multibyte locales with
1133 encodings such as GB18030. */
1135 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1136 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
1138 _GL_FUNCDECL_RPL (mbschr
, char *, (const char *string
, int c
),
1140 _GL_ARG_NONNULL ((1)));
1141 _GL_CXXALIAS_RPL (mbschr
, char *, (const char *string
, int c
));
1143 _GL_FUNCDECL_SYS (mbschr
, char *, (const char *string
, int c
),
1145 _GL_ARG_NONNULL ((1)));
1146 _GL_CXXALIAS_SYS (mbschr
, char *, (const char *string
, int c
));
1148 _GL_CXXALIASWARN (mbschr
);
1151 #if @GNULIB_MBSRCHR@
1152 /* Locate the last single-byte character C in the character string STRING,
1153 and return a pointer to it. Return NULL if C is not found in STRING.
1154 Unlike strrchr(), this function works correctly in multibyte locales with
1155 encodings such as GB18030. */
1156 # if defined __hpux || defined __INTERIX
1157 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1158 # define mbsrchr rpl_mbsrchr /* avoid collision with system function */
1160 _GL_FUNCDECL_RPL (mbsrchr
, char *, (const char *string
, int c
),
1162 _GL_ARG_NONNULL ((1)));
1163 _GL_CXXALIAS_RPL (mbsrchr
, char *, (const char *string
, int c
));
1165 _GL_FUNCDECL_SYS (mbsrchr
, char *, (const char *string
, int c
),
1167 _GL_ARG_NONNULL ((1)));
1168 _GL_CXXALIAS_SYS (mbsrchr
, char *, (const char *string
, int c
));
1170 _GL_CXXALIASWARN (mbsrchr
);
1174 /* Find the first occurrence of the character string NEEDLE in the character
1175 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
1176 Unlike strstr(), this function works correctly in multibyte locales with
1177 encodings different from UTF-8. */
1178 _GL_EXTERN_C
char * mbsstr (const char *haystack
, const char *needle
)
1180 _GL_ARG_NONNULL ((1, 2));
1183 #if @GNULIB_MBSCASECMP@
1184 /* Compare the character strings S1 and S2, ignoring case, returning less than,
1185 equal to or greater than zero if S1 is lexicographically less than, equal to
1187 Note: This function may, in multibyte locales, return 0 for strings of
1189 Unlike strcasecmp(), this function works correctly in multibyte locales. */
1190 _GL_EXTERN_C
int mbscasecmp (const char *s1
, const char *s2
)
1192 _GL_ARG_NONNULL ((1, 2));
1195 #if @GNULIB_MBSNCASECMP@
1196 /* Compare the initial segment of the character string S1 consisting of at most
1197 N characters with the initial segment of the character string S2 consisting
1198 of at most N characters, ignoring case, returning less than, equal to or
1199 greater than zero if the initial segment of S1 is lexicographically less
1200 than, equal to or greater than the initial segment of S2.
1201 Note: This function may, in multibyte locales, return 0 for initial segments
1202 of different lengths!
1203 Unlike strncasecmp(), this function works correctly in multibyte locales.
1204 But beware that N is not a byte count but a character count! */
1205 _GL_EXTERN_C
int mbsncasecmp (const char *s1
, const char *s2
, size_t n
)
1207 _GL_ARG_NONNULL ((1, 2));
1210 #if @GNULIB_MBSPCASECMP@
1211 /* Compare the initial segment of the character string STRING consisting of
1212 at most mbslen (PREFIX) characters with the character string PREFIX,
1213 ignoring case. If the two match, return a pointer to the first byte
1214 after this prefix in STRING. Otherwise, return NULL.
1215 Note: This function may, in multibyte locales, return non-NULL if STRING
1216 is of smaller length than PREFIX!
1217 Unlike strncasecmp(), this function works correctly in multibyte
1219 _GL_EXTERN_C
char * mbspcasecmp (const char *string
, const char *prefix
)
1221 _GL_ARG_NONNULL ((1, 2));
1224 #if @GNULIB_MBSCASESTR@
1225 /* Find the first occurrence of the character string NEEDLE in the character
1226 string HAYSTACK, using case-insensitive comparison.
1227 Note: This function may, in multibyte locales, return success even if
1228 strlen (haystack) < strlen (needle) !
1229 Unlike strcasestr(), this function works correctly in multibyte locales. */
1230 _GL_EXTERN_C
char * mbscasestr (const char *haystack
, const char *needle
)
1232 _GL_ARG_NONNULL ((1, 2));
1235 #if @GNULIB_MBSCSPN@
1236 /* Find the first occurrence in the character string STRING of any character
1237 in the character string ACCEPT. Return the number of bytes from the
1238 beginning of the string to this occurrence, or to the end of the string
1240 Unlike strcspn(), this function works correctly in multibyte locales. */
1241 _GL_EXTERN_C
size_t mbscspn (const char *string
, const char *accept
)
1243 _GL_ARG_NONNULL ((1, 2));
1246 #if @GNULIB_MBSPBRK@
1247 /* Find the first occurrence in the character string STRING of any character
1248 in the character string ACCEPT. Return the pointer to it, or NULL if none
1250 Unlike strpbrk(), this function works correctly in multibyte locales. */
1252 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1253 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1255 _GL_FUNCDECL_RPL (mbspbrk
, char *, (const char *string
, const char *accept
),
1257 _GL_ARG_NONNULL ((1, 2)));
1258 _GL_CXXALIAS_RPL (mbspbrk
, char *, (const char *string
, const char *accept
));
1260 _GL_FUNCDECL_SYS (mbspbrk
, char *, (const char *string
, const char *accept
),
1262 _GL_ARG_NONNULL ((1, 2)));
1263 _GL_CXXALIAS_SYS (mbspbrk
, char *, (const char *string
, const char *accept
));
1265 _GL_CXXALIASWARN (mbspbrk
);
1269 /* Find the first occurrence in the character string STRING of any character
1270 not in the character string REJECT. Return the number of bytes from the
1271 beginning of the string to this occurrence, or to the end of the string
1273 Unlike strspn(), this function works correctly in multibyte locales. */
1274 _GL_EXTERN_C
size_t mbsspn (const char *string
, const char *reject
)
1276 _GL_ARG_NONNULL ((1, 2));
1280 /* Search the next delimiter (multibyte character listed in the character
1281 string DELIM) starting at the character string *STRINGP.
1282 If one is found, overwrite it with a NUL, and advance *STRINGP to point
1283 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
1284 If *STRINGP was already NULL, nothing happens.
1285 Return the old value of *STRINGP.
1287 This is a variant of mbstok_r() that supports empty fields.
1289 Caveat: It modifies the original string.
1290 Caveat: These functions cannot be used on constant strings.
1291 Caveat: The identity of the delimiting character is lost.
1293 See also mbstok_r(). */
1294 _GL_EXTERN_C
char * mbssep (char **stringp
, const char *delim
)
1295 _GL_ARG_NONNULL ((1, 2));
1298 #if @GNULIB_MBSTOK_R@
1299 /* Parse the character string STRING into tokens separated by characters in
1300 the character string DELIM.
1301 If STRING is NULL, the saved pointer in SAVE_PTR is used as
1302 the next starting point. For example:
1303 char s[] = "-abc-=-def";
1305 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1306 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1307 x = mbstok_r(NULL, "=", &sp); // x = NULL
1308 // s = "abc\0-def\0"
1310 Caveat: It modifies the original string.
1311 Caveat: These functions cannot be used on constant strings.
1312 Caveat: The identity of the delimiting character is lost.
1314 See also mbssep(). */
1315 _GL_EXTERN_C
char * mbstok_r (char *restrict string
, const char *delim
,
1317 _GL_ARG_NONNULL ((2, 3));
1320 #if @GNULIB_MBS_STARTSWITH@
1321 /* Returns true if STRING starts with PREFIX.
1322 Returns false otherwise. */
1323 _GL_EXTERN_C
bool mbs_startswith (const char *string
, const char *prefix
)
1325 _GL_ARG_NONNULL ((1, 2));
1326 /* No extra code is needed for multibyte locales for this function. */
1327 # define mbs_startswith str_startswith
1330 #if @GNULIB_MBS_ENDSWITH@
1331 /* Returns true if STRING ends with SUFFIX.
1332 Returns false otherwise.
1333 Unlike str_endswith(), this function works correctly in multibyte locales.
1335 _GL_EXTERN_C
bool mbs_endswith (const char *string
, const char *suffix
)
1337 _GL_ARG_NONNULL ((1, 2));
1340 /* Map any int, typically from errno, into an error message. */
1341 #if @GNULIB_STRERROR@
1342 # if @REPLACE_STRERROR@
1343 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1345 # define strerror rpl_strerror
1347 _GL_FUNCDECL_RPL (strerror
, char *, (int), );
1348 _GL_CXXALIAS_RPL (strerror
, char *, (int));
1350 _GL_CXXALIAS_SYS (strerror
, char *, (int));
1353 _GL_CXXALIASWARN (strerror
);
1355 #elif defined GNULIB_POSIXCHECK
1357 /* Assume strerror is always declared. */
1358 _GL_WARN_ON_USE (strerror
, "strerror is unportable - "
1359 "use gnulib module strerror to guarantee non-NULL result");
1362 /* Map any int, typically from errno, into an error message. Multithread-safe.
1363 Uses the POSIX declaration, not the glibc declaration. */
1364 #if @GNULIB_STRERROR_R@
1365 # if @REPLACE_STRERROR_R@
1366 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1368 # define strerror_r rpl_strerror_r
1370 _GL_FUNCDECL_RPL (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
),
1371 _GL_ARG_NONNULL ((2)));
1372 _GL_CXXALIAS_RPL (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
));
1374 # if !@HAVE_DECL_STRERROR_R@
1375 _GL_FUNCDECL_SYS (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
),
1376 _GL_ARG_NONNULL ((2)));
1378 _GL_CXXALIAS_SYS (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
));
1380 # if __GLIBC__ >= 2 && @HAVE_DECL_STRERROR_R@
1381 _GL_CXXALIASWARN (strerror_r
);
1383 #elif defined GNULIB_POSIXCHECK
1385 # if HAVE_RAW_DECL_STRERROR_R
1386 _GL_WARN_ON_USE (strerror_r
, "strerror_r is unportable - "
1387 "use gnulib module strerror_r-posix for portability");
1391 /* Return the name of the system error code ERRNUM. */
1392 #if @GNULIB_STRERRORNAME_NP@
1393 # if @REPLACE_STRERRORNAME_NP@
1394 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1395 # undef strerrorname_np
1396 # define strerrorname_np rpl_strerrorname_np
1398 _GL_FUNCDECL_RPL (strerrorname_np
, const char *, (int errnum
), );
1399 _GL_CXXALIAS_RPL (strerrorname_np
, const char *, (int errnum
));
1401 # if !@HAVE_STRERRORNAME_NP@
1402 _GL_FUNCDECL_SYS (strerrorname_np
, const char *, (int errnum
), );
1404 _GL_CXXALIAS_SYS (strerrorname_np
, const char *, (int errnum
));
1406 _GL_CXXALIASWARN (strerrorname_np
);
1407 #elif defined GNULIB_POSIXCHECK
1408 # undef strerrorname_np
1409 # if HAVE_RAW_DECL_STRERRORNAME_NP
1410 _GL_WARN_ON_USE (strerrorname_np
, "strerrorname_np is unportable - "
1411 "use gnulib module strerrorname_np for portability");
1415 /* Return an abbreviation string for the signal number SIG. */
1416 #if @GNULIB_SIGABBREV_NP@
1417 # if ! @HAVE_SIGABBREV_NP@
1418 _GL_FUNCDECL_SYS (sigabbrev_np
, const char *, (int sig
), );
1420 _GL_CXXALIAS_SYS (sigabbrev_np
, const char *, (int sig
));
1421 _GL_CXXALIASWARN (sigabbrev_np
);
1422 #elif defined GNULIB_POSIXCHECK
1423 # undef sigabbrev_np
1424 # if HAVE_RAW_DECL_SIGABBREV_NP
1425 _GL_WARN_ON_USE (sigabbrev_np
, "sigabbrev_np is unportable - "
1426 "use gnulib module sigabbrev_np for portability");
1430 /* Return an English description string for the signal number SIG. */
1431 #if @GNULIB_SIGDESCR_NP@
1432 # if ! @HAVE_SIGDESCR_NP@
1433 _GL_FUNCDECL_SYS (sigdescr_np
, const char *, (int sig
), );
1435 _GL_CXXALIAS_SYS (sigdescr_np
, const char *, (int sig
));
1436 _GL_CXXALIASWARN (sigdescr_np
);
1437 #elif defined GNULIB_POSIXCHECK
1439 # if HAVE_RAW_DECL_SIGDESCR_NP
1440 _GL_WARN_ON_USE (sigdescr_np
, "sigdescr_np is unportable - "
1441 "use gnulib module sigdescr_np for portability");
1445 #if @GNULIB_STRSIGNAL@
1446 # if @REPLACE_STRSIGNAL@
1447 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1448 # define strsignal rpl_strsignal
1450 _GL_FUNCDECL_RPL (strsignal
, char *, (int __sig
), );
1451 _GL_CXXALIAS_RPL (strsignal
, char *, (int __sig
));
1453 # if ! @HAVE_DECL_STRSIGNAL@
1454 _GL_FUNCDECL_SYS (strsignal
, char *, (int __sig
), );
1456 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
1458 _GL_CXXALIAS_SYS_CAST (strsignal
, char *, (int __sig
));
1460 _GL_CXXALIASWARN (strsignal
);
1461 #elif defined GNULIB_POSIXCHECK
1463 # if HAVE_RAW_DECL_STRSIGNAL
1464 _GL_WARN_ON_USE (strsignal
, "strsignal is unportable - "
1465 "use gnulib module strsignal for portability");
1469 #if @GNULIB_STRVERSCMP@
1470 # if @REPLACE_STRVERSCMP@
1471 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1472 # define strverscmp rpl_strverscmp
1474 _GL_FUNCDECL_RPL (strverscmp
, int, (const char *, const char *),
1476 _GL_ARG_NONNULL ((1, 2)));
1477 _GL_CXXALIAS_RPL (strverscmp
, int, (const char *, const char *));
1479 # if !@HAVE_STRVERSCMP@
1480 _GL_FUNCDECL_SYS (strverscmp
, int, (const char *, const char *),
1482 _GL_ARG_NONNULL ((1, 2)));
1484 _GL_CXXALIAS_SYS (strverscmp
, int, (const char *, const char *));
1486 _GL_CXXALIASWARN (strverscmp
);
1487 #elif defined GNULIB_POSIXCHECK
1489 # if HAVE_RAW_DECL_STRVERSCMP
1490 _GL_WARN_ON_USE (strverscmp
, "strverscmp is unportable - "
1491 "use gnulib module strverscmp for portability");
1496 #endif /* _@GUARD_PREFIX@_STRING_H */
1497 #endif /* _@GUARD_PREFIX@_STRING_H */