1 /* A GNU-like <string.h>.
3 Copyright (C) 1995-1996, 2001-2024 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 _GL_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 _GL_ALREADY_INCLUDING_STRING_H
39 /* The include_next requires a split double-inclusion guard. */
40 #@INCLUDE_NEXT@ @NEXT_STRING_H@
42 #undef _GL_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
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 strdup
625 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
626 _GL_FUNCDECL_SYS (strdup
, char *,
628 _GL_ATTRIBUTE_NOTHROW
629 _GL_ARG_NONNULL ((1))
630 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
632 _GL_FUNCDECL_SYS (strdup
, char *,
634 _GL_ARG_NONNULL ((1))
635 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
638 _GL_CXXALIAS_SYS (strdup
, char *, (char const *__s
));
640 _GL_CXXALIASWARN (strdup
);
642 # if __GNUC__ >= 11 && !defined strdup
643 /* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */
644 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
645 _GL_FUNCDECL_SYS (strdup
, char *,
647 _GL_ATTRIBUTE_NOTHROW
648 _GL_ARG_NONNULL ((1))
649 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
651 _GL_FUNCDECL_SYS (strdup
, char *,
653 _GL_ARG_NONNULL ((1))
654 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
657 # if defined GNULIB_POSIXCHECK
659 # if HAVE_RAW_DECL_STRDUP
660 _GL_WARN_ON_USE (strdup
, "strdup is unportable - "
661 "use gnulib module strdup for portability");
663 # elif @GNULIB_MDA_STRDUP@
664 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
665 required. In C++ with GNULIB_NAMESPACE, avoid differences between
666 platforms by defining GNULIB_NAMESPACE::strdup always. */
667 # if defined _WIN32 && !defined __CYGWIN__
668 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
670 # define strdup _strdup
672 _GL_CXXALIAS_MDA (strdup
, char *, (char const *__s
));
674 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
677 _GL_CXXALIAS_SYS (strdup
, char *, (char const *__s
));
679 _GL_CXXALIASWARN (strdup
);
683 /* Append no more than N characters from SRC onto DEST. */
685 # if @REPLACE_STRNCAT@
686 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
688 # define strncat rpl_strncat
690 _GL_FUNCDECL_RPL (strncat
, char *,
691 (char *restrict dest
, const char *restrict src
, size_t n
)
692 _GL_ARG_NONNULL ((1, 2)));
693 _GL_CXXALIAS_RPL (strncat
, char *,
694 (char *restrict dest
, const char *restrict src
, size_t n
));
696 _GL_CXXALIAS_SYS (strncat
, char *,
697 (char *restrict dest
, const char *restrict src
, size_t n
));
700 _GL_CXXALIASWARN (strncat
);
702 #elif defined GNULIB_POSIXCHECK
704 # if HAVE_RAW_DECL_STRNCAT
705 _GL_WARN_ON_USE (strncat
, "strncat is unportable - "
706 "use gnulib module strncat for portability");
710 /* Return a newly allocated copy of at most N bytes of STRING. */
712 # if @REPLACE_STRNDUP@
713 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
715 # define strndup rpl_strndup
717 _GL_FUNCDECL_RPL (strndup
, char *,
718 (char const *__s
, size_t __n
)
719 _GL_ARG_NONNULL ((1))
720 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
721 _GL_CXXALIAS_RPL (strndup
, char *, (char const *__s
, size_t __n
));
723 # if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined strndup)
724 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
725 _GL_FUNCDECL_SYS (strndup
, char *,
726 (char const *__s
, size_t __n
)
727 _GL_ATTRIBUTE_NOTHROW
728 _GL_ARG_NONNULL ((1))
729 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
731 _GL_FUNCDECL_SYS (strndup
, char *,
732 (char const *__s
, size_t __n
)
733 _GL_ARG_NONNULL ((1))
734 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
737 _GL_CXXALIAS_SYS (strndup
, char *, (char const *__s
, size_t __n
));
739 _GL_CXXALIASWARN (strndup
);
741 # if __GNUC__ >= 11 && !defined strndup
742 /* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */
743 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
744 _GL_FUNCDECL_SYS (strndup
, char *,
745 (char const *__s
, size_t __n
)
746 _GL_ATTRIBUTE_NOTHROW
747 _GL_ARG_NONNULL ((1))
748 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
750 _GL_FUNCDECL_SYS (strndup
, char *,
751 (char const *__s
, size_t __n
)
752 _GL_ARG_NONNULL ((1))
753 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
756 # if defined GNULIB_POSIXCHECK
758 # if HAVE_RAW_DECL_STRNDUP
759 _GL_WARN_ON_USE (strndup
, "strndup is unportable - "
760 "use gnulib module strndup for portability");
765 /* Find the length (number of bytes) of STRING, but scan at most
766 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
769 # if @REPLACE_STRNLEN@
770 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
772 # define strnlen rpl_strnlen
774 _GL_FUNCDECL_RPL (strnlen
, size_t, (char const *__s
, size_t __maxlen
)
776 _GL_ARG_NONNULL ((1)));
777 _GL_CXXALIAS_RPL (strnlen
, size_t, (char const *__s
, size_t __maxlen
));
779 # if ! @HAVE_DECL_STRNLEN@
780 _GL_FUNCDECL_SYS (strnlen
, size_t, (char const *__s
, size_t __maxlen
)
782 _GL_ARG_NONNULL ((1)));
784 _GL_CXXALIAS_SYS (strnlen
, size_t, (char const *__s
, size_t __maxlen
));
786 _GL_CXXALIASWARN (strnlen
);
787 #elif defined GNULIB_POSIXCHECK
789 # if HAVE_RAW_DECL_STRNLEN
790 _GL_WARN_ON_USE (strnlen
, "strnlen is unportable - "
791 "use gnulib module strnlen for portability");
795 #if defined GNULIB_POSIXCHECK
796 /* strcspn() assumes the second argument is a list of single-byte characters.
797 Even in this simple case, it does not work with multibyte strings if the
798 locale encoding is GB18030 and one of the characters to be searched is a
801 /* Assume strcspn is always declared. */
802 _GL_WARN_ON_USE (strcspn
, "strcspn cannot work correctly on character strings "
803 "in multibyte locales - "
804 "use mbscspn if you care about internationalization");
807 /* Find the first occurrence in S of any character in ACCEPT. */
809 # if ! @HAVE_STRPBRK@
810 _GL_FUNCDECL_SYS (strpbrk
, char *, (char const *__s
, char const *__accept
)
812 _GL_ARG_NONNULL ((1, 2)));
814 /* On some systems, this function is defined as an overloaded function:
815 extern "C" { const char * strpbrk (const char *, const char *); }
816 extern "C++" { char * strpbrk (char *, const char *); } */
817 _GL_CXXALIAS_SYS_CAST2 (strpbrk
,
818 char *, (char const *__s
, char const *__accept
),
819 const char *, (char const *__s
, char const *__accept
));
820 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
821 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
822 || defined __clang__)
823 _GL_CXXALIASWARN1 (strpbrk
, char *,
824 (char *__s
, char const *__accept
)
825 _GL_ATTRIBUTE_NOTHROW
);
826 _GL_CXXALIASWARN1 (strpbrk
, char const *,
827 (char const *__s
, char const *__accept
)
828 _GL_ATTRIBUTE_NOTHROW
);
829 # elif __GLIBC__ >= 2
830 _GL_CXXALIASWARN (strpbrk
);
832 # if defined GNULIB_POSIXCHECK
833 /* strpbrk() assumes the second argument is a list of single-byte characters.
834 Even in this simple case, it does not work with multibyte strings if the
835 locale encoding is GB18030 and one of the characters to be searched is a
838 _GL_WARN_ON_USE_CXX (strpbrk
,
839 const char *, char *, (const char *, const char *),
840 "strpbrk cannot work correctly on character strings "
841 "in multibyte locales - "
842 "use mbspbrk if you care about internationalization");
844 #elif defined GNULIB_POSIXCHECK
846 # if HAVE_RAW_DECL_STRPBRK
847 _GL_WARN_ON_USE_CXX (strpbrk
,
848 const char *, char *, (const char *, const char *),
849 "strpbrk is unportable - "
850 "use gnulib module strpbrk for portability");
854 #if defined GNULIB_POSIXCHECK
855 /* strspn() assumes the second argument is a list of single-byte characters.
856 Even in this simple case, it cannot work with multibyte strings. */
858 /* Assume strspn is always declared. */
859 _GL_WARN_ON_USE (strspn
, "strspn cannot work correctly on character strings "
860 "in multibyte locales - "
861 "use mbsspn if you care about internationalization");
864 #if defined GNULIB_POSIXCHECK
865 /* strrchr() does not work with multibyte strings if the locale encoding is
866 GB18030 and the character to be searched is a digit. */
868 /* Assume strrchr is always declared. */
869 _GL_WARN_ON_USE_CXX (strrchr
,
870 const char *, char *, (const char *, int),
871 "strrchr cannot work correctly on character strings "
872 "in some multibyte locales - "
873 "use mbsrchr if you care about internationalization");
876 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
877 If one is found, overwrite it with a NUL, and advance *STRINGP
878 to point to the next char after it. Otherwise, set *STRINGP to NULL.
879 If *STRINGP was already NULL, nothing happens.
880 Return the old value of *STRINGP.
882 This is a variant of strtok() that is multithread-safe and supports
885 Caveat: It modifies the original string.
886 Caveat: These functions cannot be used on constant strings.
887 Caveat: The identity of the delimiting character is lost.
888 Caveat: It doesn't work with multibyte strings unless all of the delimiter
889 characters are ASCII characters < 0x30.
891 See also strtok_r(). */
894 _GL_FUNCDECL_SYS (strsep
, char *,
895 (char **restrict __stringp
, char const *restrict __delim
)
896 _GL_ARG_NONNULL ((1, 2)));
898 _GL_CXXALIAS_SYS (strsep
, char *,
899 (char **restrict __stringp
, char const *restrict __delim
));
900 _GL_CXXALIASWARN (strsep
);
901 # if defined GNULIB_POSIXCHECK
903 _GL_WARN_ON_USE (strsep
, "strsep cannot work correctly on character strings "
904 "in multibyte locales - "
905 "use mbssep if you care about internationalization");
907 #elif defined GNULIB_POSIXCHECK
909 # if HAVE_RAW_DECL_STRSEP
910 _GL_WARN_ON_USE (strsep
, "strsep is unportable - "
911 "use gnulib module strsep for portability");
916 # if @REPLACE_STRSTR@
917 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
918 # define strstr rpl_strstr
920 _GL_FUNCDECL_RPL (strstr
, char *, (const char *haystack
, const char *needle
)
922 _GL_ARG_NONNULL ((1, 2)));
923 _GL_CXXALIAS_RPL (strstr
, char *, (const char *haystack
, const char *needle
));
925 /* On some systems, this function is defined as an overloaded function:
926 extern "C++" { const char * strstr (const char *, const char *); }
927 extern "C++" { char * strstr (char *, const char *); } */
928 _GL_CXXALIAS_SYS_CAST2 (strstr
,
929 char *, (const char *haystack
, const char *needle
),
930 const char *, (const char *haystack
, const char *needle
));
932 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
933 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
934 || defined __clang__)
935 _GL_CXXALIASWARN1 (strstr
, char *,
936 (char *haystack
, const char *needle
)
937 _GL_ATTRIBUTE_NOTHROW
);
938 _GL_CXXALIASWARN1 (strstr
, const char *,
939 (const char *haystack
, const char *needle
)
940 _GL_ATTRIBUTE_NOTHROW
);
941 # elif __GLIBC__ >= 2
942 _GL_CXXALIASWARN (strstr
);
944 #elif defined GNULIB_POSIXCHECK
945 /* strstr() does not work with multibyte strings if the locale encoding is
946 different from UTF-8:
947 POSIX says that it operates on "strings", and "string" in POSIX is defined
948 as a sequence of bytes, not of characters. */
950 /* Assume strstr is always declared. */
951 _GL_WARN_ON_USE (strstr
, "strstr is quadratic on many systems, and cannot "
952 "work correctly on character strings in most "
953 "multibyte locales - "
954 "use mbsstr if you care about internationalization, "
955 "or use strstr if you care about speed");
958 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
960 #if @GNULIB_STRCASESTR@
961 # if @REPLACE_STRCASESTR@
962 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
963 # define strcasestr rpl_strcasestr
965 _GL_FUNCDECL_RPL (strcasestr
, char *,
966 (const char *haystack
, const char *needle
)
968 _GL_ARG_NONNULL ((1, 2)));
969 _GL_CXXALIAS_RPL (strcasestr
, char *,
970 (const char *haystack
, const char *needle
));
972 # if ! @HAVE_STRCASESTR@
973 _GL_FUNCDECL_SYS (strcasestr
, char *,
974 (const char *haystack
, const char *needle
)
976 _GL_ARG_NONNULL ((1, 2)));
978 /* On some systems, this function is defined as an overloaded function:
979 extern "C++" { const char * strcasestr (const char *, const char *); }
980 extern "C++" { char * strcasestr (char *, const char *); } */
981 _GL_CXXALIAS_SYS_CAST2 (strcasestr
,
982 char *, (const char *haystack
, const char *needle
),
983 const char *, (const char *haystack
, const char *needle
));
985 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
986 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
987 || defined __clang__)
988 _GL_CXXALIASWARN1 (strcasestr
, char *,
989 (char *haystack
, const char *needle
)
990 _GL_ATTRIBUTE_NOTHROW
);
991 _GL_CXXALIASWARN1 (strcasestr
, const char *,
992 (const char *haystack
, const char *needle
)
993 _GL_ATTRIBUTE_NOTHROW
);
994 # elif __GLIBC__ >= 2
995 _GL_CXXALIASWARN (strcasestr
);
997 #elif defined GNULIB_POSIXCHECK
998 /* strcasestr() does not work with multibyte strings:
999 It is a glibc extension, and glibc implements it only for unibyte
1002 # if HAVE_RAW_DECL_STRCASESTR
1003 _GL_WARN_ON_USE (strcasestr
, "strcasestr does work correctly on character "
1004 "strings in multibyte locales - "
1005 "use mbscasestr if you care about "
1006 "internationalization, or use c-strcasestr if you want "
1007 "a locale independent function");
1011 /* Parse S into tokens separated by characters in DELIM.
1012 If S is NULL, the saved pointer in SAVE_PTR is used as
1013 the next starting point. For example:
1014 char s[] = "-abc-=-def";
1016 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1017 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1018 x = strtok_r(NULL, "=", &sp); // x = NULL
1019 // s = "abc\0-def\0"
1021 This is a variant of strtok() that is multithread-safe.
1023 For the POSIX documentation for this function, see:
1024 https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html
1026 Caveat: It modifies the original string.
1027 Caveat: These functions cannot be used on constant strings.
1028 Caveat: The identity of the delimiting character is lost.
1029 Caveat: It doesn't work with multibyte strings unless all of the delimiter
1030 characters are ASCII characters < 0x30.
1032 See also strsep(). */
1033 #if @GNULIB_STRTOK_R@
1034 # if @REPLACE_STRTOK_R@
1035 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1037 # define strtok_r rpl_strtok_r
1039 _GL_FUNCDECL_RPL (strtok_r
, char *,
1040 (char *restrict s
, char const *restrict delim
,
1041 char **restrict save_ptr
)
1042 _GL_ARG_NONNULL ((2, 3)));
1043 _GL_CXXALIAS_RPL (strtok_r
, char *,
1044 (char *restrict s
, char const *restrict delim
,
1045 char **restrict save_ptr
));
1047 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
1050 # if ! @HAVE_DECL_STRTOK_R@
1051 _GL_FUNCDECL_SYS (strtok_r
, char *,
1052 (char *restrict s
, char const *restrict delim
,
1053 char **restrict save_ptr
)
1054 _GL_ARG_NONNULL ((2, 3)));
1056 _GL_CXXALIAS_SYS (strtok_r
, char *,
1057 (char *restrict s
, char const *restrict delim
,
1058 char **restrict save_ptr
));
1060 _GL_CXXALIASWARN (strtok_r
);
1061 # if defined GNULIB_POSIXCHECK
1062 _GL_WARN_ON_USE (strtok_r
, "strtok_r cannot work correctly on character "
1063 "strings in multibyte locales - "
1064 "use mbstok_r if you care about internationalization");
1066 #elif defined GNULIB_POSIXCHECK
1068 # if HAVE_RAW_DECL_STRTOK_R
1069 _GL_WARN_ON_USE (strtok_r
, "strtok_r is unportable - "
1070 "use gnulib module strtok_r for portability");
1075 /* The following functions are not specified by POSIX. They are gnulib
1079 /* Return the number of multibyte characters in the character string STRING.
1080 This considers multibyte characters, unlike strlen, which counts bytes. */
1081 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
1084 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
1085 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1086 # define mbslen rpl_mbslen
1088 _GL_FUNCDECL_RPL (mbslen
, size_t, (const char *string
)
1090 _GL_ARG_NONNULL ((1)));
1091 _GL_CXXALIAS_RPL (mbslen
, size_t, (const char *string
));
1093 _GL_FUNCDECL_SYS (mbslen
, size_t, (const char *string
)
1095 _GL_ARG_NONNULL ((1)));
1096 _GL_CXXALIAS_SYS (mbslen
, size_t, (const char *string
));
1099 _GL_CXXALIASWARN (mbslen
);
1103 #if @GNULIB_MBSNLEN@
1104 /* Return the number of multibyte characters in the character string starting
1105 at STRING and ending at STRING + LEN. */
1106 _GL_EXTERN_C
size_t mbsnlen (const char *string
, size_t len
)
1108 _GL_ARG_NONNULL ((1));
1112 /* Locate the first single-byte character C in the character string STRING,
1113 and return a pointer to it. Return NULL if C is not found in STRING.
1114 Unlike strchr(), this function works correctly in multibyte locales with
1115 encodings such as GB18030. */
1117 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1118 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
1120 _GL_FUNCDECL_RPL (mbschr
, char *, (const char *string
, int c
)
1122 _GL_ARG_NONNULL ((1)));
1123 _GL_CXXALIAS_RPL (mbschr
, char *, (const char *string
, int c
));
1125 _GL_FUNCDECL_SYS (mbschr
, char *, (const char *string
, int c
)
1127 _GL_ARG_NONNULL ((1)));
1128 _GL_CXXALIAS_SYS (mbschr
, char *, (const char *string
, int c
));
1130 _GL_CXXALIASWARN (mbschr
);
1133 #if @GNULIB_MBSRCHR@
1134 /* Locate the last single-byte character C in the character string STRING,
1135 and return a pointer to it. Return NULL if C is not found in STRING.
1136 Unlike strrchr(), this function works correctly in multibyte locales with
1137 encodings such as GB18030. */
1138 # if defined __hpux || defined __INTERIX
1139 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1140 # define mbsrchr rpl_mbsrchr /* avoid collision with system function */
1142 _GL_FUNCDECL_RPL (mbsrchr
, char *, (const char *string
, int c
)
1144 _GL_ARG_NONNULL ((1)));
1145 _GL_CXXALIAS_RPL (mbsrchr
, char *, (const char *string
, int c
));
1147 _GL_FUNCDECL_SYS (mbsrchr
, char *, (const char *string
, int c
)
1149 _GL_ARG_NONNULL ((1)));
1150 _GL_CXXALIAS_SYS (mbsrchr
, char *, (const char *string
, int c
));
1152 _GL_CXXALIASWARN (mbsrchr
);
1156 /* Find the first occurrence of the character string NEEDLE in the character
1157 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
1158 Unlike strstr(), this function works correctly in multibyte locales with
1159 encodings different from UTF-8. */
1160 _GL_EXTERN_C
char * mbsstr (const char *haystack
, const char *needle
)
1162 _GL_ARG_NONNULL ((1, 2));
1165 #if @GNULIB_MBSCASECMP@
1166 /* Compare the character strings S1 and S2, ignoring case, returning less than,
1167 equal to or greater than zero if S1 is lexicographically less than, equal to
1169 Note: This function may, in multibyte locales, return 0 for strings of
1171 Unlike strcasecmp(), this function works correctly in multibyte locales. */
1172 _GL_EXTERN_C
int mbscasecmp (const char *s1
, const char *s2
)
1174 _GL_ARG_NONNULL ((1, 2));
1177 #if @GNULIB_MBSNCASECMP@
1178 /* Compare the initial segment of the character string S1 consisting of at most
1179 N characters with the initial segment of the character string S2 consisting
1180 of at most N characters, ignoring case, returning less than, equal to or
1181 greater than zero if the initial segment of S1 is lexicographically less
1182 than, equal to or greater than the initial segment of S2.
1183 Note: This function may, in multibyte locales, return 0 for initial segments
1184 of different lengths!
1185 Unlike strncasecmp(), this function works correctly in multibyte locales.
1186 But beware that N is not a byte count but a character count! */
1187 _GL_EXTERN_C
int mbsncasecmp (const char *s1
, const char *s2
, size_t n
)
1189 _GL_ARG_NONNULL ((1, 2));
1192 #if @GNULIB_MBSPCASECMP@
1193 /* Compare the initial segment of the character string STRING consisting of
1194 at most mbslen (PREFIX) characters with the character string PREFIX,
1195 ignoring case. If the two match, return a pointer to the first byte
1196 after this prefix in STRING. Otherwise, return NULL.
1197 Note: This function may, in multibyte locales, return non-NULL if STRING
1198 is of smaller length than PREFIX!
1199 Unlike strncasecmp(), this function works correctly in multibyte
1201 _GL_EXTERN_C
char * mbspcasecmp (const char *string
, const char *prefix
)
1203 _GL_ARG_NONNULL ((1, 2));
1206 #if @GNULIB_MBSCASESTR@
1207 /* Find the first occurrence of the character string NEEDLE in the character
1208 string HAYSTACK, using case-insensitive comparison.
1209 Note: This function may, in multibyte locales, return success even if
1210 strlen (haystack) < strlen (needle) !
1211 Unlike strcasestr(), this function works correctly in multibyte locales. */
1212 _GL_EXTERN_C
char * mbscasestr (const char *haystack
, const char *needle
)
1214 _GL_ARG_NONNULL ((1, 2));
1217 #if @GNULIB_MBSCSPN@
1218 /* Find the first occurrence in the character string STRING of any character
1219 in the character string ACCEPT. Return the number of bytes from the
1220 beginning of the string to this occurrence, or to the end of the string
1222 Unlike strcspn(), this function works correctly in multibyte locales. */
1223 _GL_EXTERN_C
size_t mbscspn (const char *string
, const char *accept
)
1225 _GL_ARG_NONNULL ((1, 2));
1228 #if @GNULIB_MBSPBRK@
1229 /* Find the first occurrence in the character string STRING of any character
1230 in the character string ACCEPT. Return the pointer to it, or NULL if none
1232 Unlike strpbrk(), this function works correctly in multibyte locales. */
1234 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1235 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1237 _GL_FUNCDECL_RPL (mbspbrk
, char *, (const char *string
, const char *accept
)
1239 _GL_ARG_NONNULL ((1, 2)));
1240 _GL_CXXALIAS_RPL (mbspbrk
, char *, (const char *string
, const char *accept
));
1242 _GL_FUNCDECL_SYS (mbspbrk
, char *, (const char *string
, const char *accept
)
1244 _GL_ARG_NONNULL ((1, 2)));
1245 _GL_CXXALIAS_SYS (mbspbrk
, char *, (const char *string
, const char *accept
));
1247 _GL_CXXALIASWARN (mbspbrk
);
1251 /* Find the first occurrence in the character string STRING of any character
1252 not in the character string REJECT. Return the number of bytes from the
1253 beginning of the string to this occurrence, or to the end of the string
1255 Unlike strspn(), this function works correctly in multibyte locales. */
1256 _GL_EXTERN_C
size_t mbsspn (const char *string
, const char *reject
)
1258 _GL_ARG_NONNULL ((1, 2));
1262 /* Search the next delimiter (multibyte character listed in the character
1263 string DELIM) starting at the character string *STRINGP.
1264 If one is found, overwrite it with a NUL, and advance *STRINGP to point
1265 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
1266 If *STRINGP was already NULL, nothing happens.
1267 Return the old value of *STRINGP.
1269 This is a variant of mbstok_r() that supports empty fields.
1271 Caveat: It modifies the original string.
1272 Caveat: These functions cannot be used on constant strings.
1273 Caveat: The identity of the delimiting character is lost.
1275 See also mbstok_r(). */
1276 _GL_EXTERN_C
char * mbssep (char **stringp
, const char *delim
)
1277 _GL_ARG_NONNULL ((1, 2));
1280 #if @GNULIB_MBSTOK_R@
1281 /* Parse the character string STRING into tokens separated by characters in
1282 the character string DELIM.
1283 If STRING is NULL, the saved pointer in SAVE_PTR is used as
1284 the next starting point. For example:
1285 char s[] = "-abc-=-def";
1287 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1288 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1289 x = mbstok_r(NULL, "=", &sp); // x = NULL
1290 // s = "abc\0-def\0"
1292 Caveat: It modifies the original string.
1293 Caveat: These functions cannot be used on constant strings.
1294 Caveat: The identity of the delimiting character is lost.
1296 See also mbssep(). */
1297 _GL_EXTERN_C
char * mbstok_r (char *restrict string
, const char *delim
,
1299 _GL_ARG_NONNULL ((2, 3));
1302 /* Map any int, typically from errno, into an error message. */
1303 #if @GNULIB_STRERROR@
1304 # if @REPLACE_STRERROR@
1305 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1307 # define strerror rpl_strerror
1309 _GL_FUNCDECL_RPL (strerror
, char *, (int));
1310 _GL_CXXALIAS_RPL (strerror
, char *, (int));
1312 _GL_CXXALIAS_SYS (strerror
, char *, (int));
1315 _GL_CXXALIASWARN (strerror
);
1317 #elif defined GNULIB_POSIXCHECK
1319 /* Assume strerror is always declared. */
1320 _GL_WARN_ON_USE (strerror
, "strerror is unportable - "
1321 "use gnulib module strerror to guarantee non-NULL result");
1324 /* Map any int, typically from errno, into an error message. Multithread-safe.
1325 Uses the POSIX declaration, not the glibc declaration. */
1326 #if @GNULIB_STRERROR_R@
1327 # if @REPLACE_STRERROR_R@
1328 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1330 # define strerror_r rpl_strerror_r
1332 _GL_FUNCDECL_RPL (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
)
1333 _GL_ARG_NONNULL ((2)));
1334 _GL_CXXALIAS_RPL (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
));
1336 # if !@HAVE_DECL_STRERROR_R@
1337 _GL_FUNCDECL_SYS (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
)
1338 _GL_ARG_NONNULL ((2)));
1340 _GL_CXXALIAS_SYS (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
));
1342 # if __GLIBC__ >= 2 && @HAVE_DECL_STRERROR_R@
1343 _GL_CXXALIASWARN (strerror_r
);
1345 #elif defined GNULIB_POSIXCHECK
1347 # if HAVE_RAW_DECL_STRERROR_R
1348 _GL_WARN_ON_USE (strerror_r
, "strerror_r is unportable - "
1349 "use gnulib module strerror_r-posix for portability");
1353 /* Return the name of the system error code ERRNUM. */
1354 #if @GNULIB_STRERRORNAME_NP@
1355 # if @REPLACE_STRERRORNAME_NP@
1356 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1357 # undef strerrorname_np
1358 # define strerrorname_np rpl_strerrorname_np
1360 _GL_FUNCDECL_RPL (strerrorname_np
, const char *, (int errnum
));
1361 _GL_CXXALIAS_RPL (strerrorname_np
, const char *, (int errnum
));
1363 # if !@HAVE_STRERRORNAME_NP@
1364 _GL_FUNCDECL_SYS (strerrorname_np
, const char *, (int errnum
));
1366 _GL_CXXALIAS_SYS (strerrorname_np
, const char *, (int errnum
));
1368 _GL_CXXALIASWARN (strerrorname_np
);
1369 #elif defined GNULIB_POSIXCHECK
1370 # undef strerrorname_np
1371 # if HAVE_RAW_DECL_STRERRORNAME_NP
1372 _GL_WARN_ON_USE (strerrorname_np
, "strerrorname_np is unportable - "
1373 "use gnulib module strerrorname_np for portability");
1377 /* Return an abbreviation string for the signal number SIG. */
1378 #if @GNULIB_SIGABBREV_NP@
1379 # if ! @HAVE_SIGABBREV_NP@
1380 _GL_FUNCDECL_SYS (sigabbrev_np
, const char *, (int sig
));
1382 _GL_CXXALIAS_SYS (sigabbrev_np
, const char *, (int sig
));
1383 _GL_CXXALIASWARN (sigabbrev_np
);
1384 #elif defined GNULIB_POSIXCHECK
1385 # undef sigabbrev_np
1386 # if HAVE_RAW_DECL_SIGABBREV_NP
1387 _GL_WARN_ON_USE (sigabbrev_np
, "sigabbrev_np is unportable - "
1388 "use gnulib module sigabbrev_np for portability");
1392 /* Return an English description string for the signal number SIG. */
1393 #if @GNULIB_SIGDESCR_NP@
1394 # if ! @HAVE_SIGDESCR_NP@
1395 _GL_FUNCDECL_SYS (sigdescr_np
, const char *, (int sig
));
1397 _GL_CXXALIAS_SYS (sigdescr_np
, const char *, (int sig
));
1398 _GL_CXXALIASWARN (sigdescr_np
);
1399 #elif defined GNULIB_POSIXCHECK
1401 # if HAVE_RAW_DECL_SIGDESCR_NP
1402 _GL_WARN_ON_USE (sigdescr_np
, "sigdescr_np is unportable - "
1403 "use gnulib module sigdescr_np for portability");
1407 #if @GNULIB_STRSIGNAL@
1408 # if @REPLACE_STRSIGNAL@
1409 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1410 # define strsignal rpl_strsignal
1412 _GL_FUNCDECL_RPL (strsignal
, char *, (int __sig
));
1413 _GL_CXXALIAS_RPL (strsignal
, char *, (int __sig
));
1415 # if ! @HAVE_DECL_STRSIGNAL@
1416 _GL_FUNCDECL_SYS (strsignal
, char *, (int __sig
));
1418 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
1420 _GL_CXXALIAS_SYS_CAST (strsignal
, char *, (int __sig
));
1422 _GL_CXXALIASWARN (strsignal
);
1423 #elif defined GNULIB_POSIXCHECK
1425 # if HAVE_RAW_DECL_STRSIGNAL
1426 _GL_WARN_ON_USE (strsignal
, "strsignal is unportable - "
1427 "use gnulib module strsignal for portability");
1431 #if @GNULIB_STRVERSCMP@
1432 # if @REPLACE_STRVERSCMP@
1433 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1434 # define strverscmp rpl_strverscmp
1436 _GL_FUNCDECL_RPL (strverscmp
, int, (const char *, const char *)
1438 _GL_ARG_NONNULL ((1, 2)));
1439 _GL_CXXALIAS_RPL (strverscmp
, int, (const char *, const char *));
1441 # if !@HAVE_STRVERSCMP@
1442 _GL_FUNCDECL_SYS (strverscmp
, int, (const char *, const char *)
1444 _GL_ARG_NONNULL ((1, 2)));
1446 _GL_CXXALIAS_SYS (strverscmp
, int, (const char *, const char *));
1448 _GL_CXXALIASWARN (strverscmp
);
1449 #elif defined GNULIB_POSIXCHECK
1451 # if HAVE_RAW_DECL_STRVERSCMP
1452 _GL_WARN_ON_USE (strverscmp
, "strverscmp is unportable - "
1453 "use gnulib module strverscmp for portability");
1458 #endif /* _@GUARD_PREFIX@_STRING_H */
1459 #endif /* _@GUARD_PREFIX@_STRING_H */