1 /* A GNU-like <string.h>.
3 Copyright (C) 1995-1996, 2001-2023 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 /* NetBSD 5.0 mis-defines NULL. */
50 /* MirBSD defines mbslen as a macro. */
51 #if @GNULIB_MBSLEN@ && defined __MirBSD__
55 /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
56 /* But in any case avoid namespace pollution on glibc systems. */
57 #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
58 && ! defined __GLIBC__
62 /* AIX 7.2 declares ffsl and ffsll in <strings.h>, not in <string.h>. */
63 /* But in any case avoid namespace pollution on glibc systems. */
64 #if ((@GNULIB_FFSL@ || @GNULIB_FFSLL@ || defined GNULIB_POSIXCHECK) \
66 && ! defined __GLIBC__
70 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
71 that can be freed by passing them as the Ith argument to the
73 #ifndef _GL_ATTRIBUTE_DEALLOC
75 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
77 # define _GL_ATTRIBUTE_DEALLOC(f, i)
81 /* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
82 can be freed via 'free'; it can be used only after declaring 'free'. */
83 /* Applies to: functions. Cannot be used on inline functions. */
84 #ifndef _GL_ATTRIBUTE_DEALLOC_FREE
85 # if defined __cplusplus && defined __GNUC__ && !defined __clang__
86 /* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
87 # define _GL_ATTRIBUTE_DEALLOC_FREE \
88 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
90 # define _GL_ATTRIBUTE_DEALLOC_FREE \
91 _GL_ATTRIBUTE_DEALLOC (free, 1)
95 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
97 /* Applies to: functions. */
98 #ifndef _GL_ATTRIBUTE_MALLOC
99 # if __GNUC__ >= 3 || defined __clang__
100 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
102 # define _GL_ATTRIBUTE_MALLOC
106 /* The __attribute__ feature is available in gcc versions 2.5 and later.
107 The attribute __pure__ was added in gcc 2.96. */
108 #ifndef _GL_ATTRIBUTE_PURE
109 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
110 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
112 # define _GL_ATTRIBUTE_PURE /* empty */
116 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
118 /* The definition of _GL_ARG_NONNULL is copied here. */
120 /* The definition of _GL_WARN_ON_USE is copied here. */
122 /* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though <stdlib.h> may not have
123 been included yet. */
124 #if @GNULIB_FREE_POSIX@
125 # if (@REPLACE_FREE@ && !defined free \
126 && !(defined __cplusplus && defined GNULIB_NAMESPACE))
127 /* We can't do '#define free rpl_free' here. */
128 _GL_EXTERN_C
void rpl_free (void *);
129 # undef _GL_ATTRIBUTE_DEALLOC_FREE
130 # define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
132 # if defined _MSC_VER && !defined free
135 __declspec (dllimport
)
137 void __cdecl
free (void *);
139 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
140 _GL_EXTERN_C
void free (void *) throw ();
142 _GL_EXTERN_C
void free (void *);
147 # if defined _MSC_VER && !defined free
150 __declspec (dllimport
)
152 void __cdecl
free (void *);
154 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
155 _GL_EXTERN_C
void free (void *) throw ();
157 _GL_EXTERN_C
void free (void *);
162 /* Clear a block of memory. The compiler will not delete a call to
163 this function, even if the block is dead after the call. */
164 #if @GNULIB_EXPLICIT_BZERO@
165 # if ! @HAVE_EXPLICIT_BZERO@
166 _GL_FUNCDECL_SYS (explicit_bzero
, void,
167 (void *__dest
, size_t __n
) _GL_ARG_NONNULL ((1)));
169 _GL_CXXALIAS_SYS (explicit_bzero
, void, (void *__dest
, size_t __n
));
170 _GL_CXXALIASWARN (explicit_bzero
);
171 #elif defined GNULIB_POSIXCHECK
172 # undef explicit_bzero
173 # if HAVE_RAW_DECL_EXPLICIT_BZERO
174 _GL_WARN_ON_USE (explicit_bzero
, "explicit_bzero is unportable - "
175 "use gnulib module explicit_bzero for portability");
179 /* Find the index of the least-significant set bit. */
182 _GL_FUNCDECL_SYS (ffsl
, int, (long int i
));
184 _GL_CXXALIAS_SYS (ffsl
, int, (long int i
));
185 _GL_CXXALIASWARN (ffsl
);
186 #elif defined GNULIB_POSIXCHECK
188 # if HAVE_RAW_DECL_FFSL
189 _GL_WARN_ON_USE (ffsl
, "ffsl is not portable - use the ffsl module");
194 /* Find the index of the least-significant set bit. */
197 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
198 # define ffsll rpl_ffsll
200 _GL_FUNCDECL_RPL (ffsll
, int, (long long int i
));
201 _GL_CXXALIAS_RPL (ffsll
, int, (long long int i
));
204 _GL_FUNCDECL_SYS (ffsll
, int, (long long int i
));
206 _GL_CXXALIAS_SYS (ffsll
, int, (long long int i
));
208 _GL_CXXALIASWARN (ffsll
);
209 #elif defined GNULIB_POSIXCHECK
211 # if HAVE_RAW_DECL_FFSLL
212 _GL_WARN_ON_USE (ffsll
, "ffsll is not portable - use the ffsll module");
217 #if @GNULIB_MDA_MEMCCPY@
218 /* On native Windows, map 'memccpy' to '_memccpy', so that -loldnames is not
219 required. In C++ with GNULIB_NAMESPACE, avoid differences between
220 platforms by defining GNULIB_NAMESPACE::memccpy always. */
221 # if defined _WIN32 && !defined __CYGWIN__
222 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224 # define memccpy _memccpy
226 _GL_CXXALIAS_MDA (memccpy
, void *,
227 (void *dest
, const void *src
, int c
, size_t n
));
229 _GL_CXXALIAS_SYS (memccpy
, void *,
230 (void *dest
, const void *src
, int c
, size_t n
));
232 _GL_CXXALIASWARN (memccpy
);
236 /* Return the first instance of C within N bytes of S, or NULL. */
238 # if @REPLACE_MEMCHR@
239 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
241 # define memchr rpl_memchr
243 _GL_FUNCDECL_RPL (memchr
, void *, (void const *__s
, int __c
, size_t __n
)
245 _GL_ARG_NONNULL ((1)));
246 _GL_CXXALIAS_RPL (memchr
, void *, (void const *__s
, int __c
, size_t __n
));
248 /* On some systems, this function is defined as an overloaded function:
249 extern "C" { const void * std::memchr (const void *, int, size_t); }
250 extern "C++" { void * std::memchr (void *, int, size_t); } */
251 _GL_CXXALIAS_SYS_CAST2 (memchr
,
252 void *, (void const *__s
, int __c
, size_t __n
),
253 void const *, (void const *__s
, int __c
, size_t __n
));
255 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
256 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
257 || defined __clang__)
258 _GL_CXXALIASWARN1 (memchr
, void *, (void *__s
, int __c
, size_t __n
) throw ());
259 _GL_CXXALIASWARN1 (memchr
, void const *,
260 (void const *__s
, int __c
, size_t __n
) throw ());
261 # elif __GLIBC__ >= 2
262 _GL_CXXALIASWARN (memchr
);
264 #elif defined GNULIB_POSIXCHECK
266 /* Assume memchr is always declared. */
267 _GL_WARN_ON_USE (memchr
, "memchr has platform-specific bugs - "
268 "use gnulib module memchr for portability" );
271 /* Return the first occurrence of NEEDLE in HAYSTACK. */
273 # if @REPLACE_MEMMEM@
274 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
275 # define memmem rpl_memmem
277 _GL_FUNCDECL_RPL (memmem
, void *,
278 (void const *__haystack
, size_t __haystack_len
,
279 void const *__needle
, size_t __needle_len
)
281 _GL_ARG_NONNULL ((1, 3)));
282 _GL_CXXALIAS_RPL (memmem
, void *,
283 (void const *__haystack
, size_t __haystack_len
,
284 void const *__needle
, size_t __needle_len
));
286 # if ! @HAVE_DECL_MEMMEM@
287 _GL_FUNCDECL_SYS (memmem
, void *,
288 (void const *__haystack
, size_t __haystack_len
,
289 void const *__needle
, size_t __needle_len
)
291 _GL_ARG_NONNULL ((1, 3)));
293 _GL_CXXALIAS_SYS (memmem
, void *,
294 (void const *__haystack
, size_t __haystack_len
,
295 void const *__needle
, size_t __needle_len
));
297 _GL_CXXALIASWARN (memmem
);
298 #elif defined GNULIB_POSIXCHECK
300 # if HAVE_RAW_DECL_MEMMEM
301 _GL_WARN_ON_USE (memmem
, "memmem is unportable and often quadratic - "
302 "use gnulib module memmem-simple for portability, "
303 "and module memmem for speed" );
307 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
308 last written byte. */
310 # if ! @HAVE_MEMPCPY@
311 _GL_FUNCDECL_SYS (mempcpy
, void *,
312 (void *restrict __dest
, void const *restrict __src
,
314 _GL_ARG_NONNULL ((1, 2)));
316 _GL_CXXALIAS_SYS (mempcpy
, void *,
317 (void *restrict __dest
, void const *restrict __src
,
319 _GL_CXXALIASWARN (mempcpy
);
320 #elif defined GNULIB_POSIXCHECK
322 # if HAVE_RAW_DECL_MEMPCPY
323 _GL_WARN_ON_USE (mempcpy
, "mempcpy is unportable - "
324 "use gnulib module mempcpy for portability");
328 /* Search backwards through a block for a byte (specified as an int). */
330 # if ! @HAVE_DECL_MEMRCHR@
331 _GL_FUNCDECL_SYS (memrchr
, void *, (void const *, int, size_t)
333 _GL_ARG_NONNULL ((1)));
335 /* On some systems, this function is defined as an overloaded function:
336 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
337 extern "C++" { void * std::memrchr (void *, int, size_t); } */
338 _GL_CXXALIAS_SYS_CAST2 (memrchr
,
339 void *, (void const *, int, size_t),
340 void const *, (void const *, int, size_t));
341 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
342 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
343 || defined __clang__)
344 _GL_CXXALIASWARN1 (memrchr
, void *, (void *, int, size_t) throw ());
345 _GL_CXXALIASWARN1 (memrchr
, void const *, (void const *, int, size_t) throw ());
347 _GL_CXXALIASWARN (memrchr
);
349 #elif defined GNULIB_POSIXCHECK
351 # if HAVE_RAW_DECL_MEMRCHR
352 _GL_WARN_ON_USE (memrchr
, "memrchr is unportable - "
353 "use gnulib module memrchr for portability");
357 /* Overwrite a block of memory. The compiler will not optimize
358 effects away, even if the block is dead after the call. */
359 #if @GNULIB_MEMSET_EXPLICIT@
360 # if ! @HAVE_MEMSET_EXPLICIT@
361 _GL_FUNCDECL_SYS (memset_explicit
, void *,
362 (void *__dest
, int __c
, size_t __n
) _GL_ARG_NONNULL ((1)));
364 _GL_CXXALIAS_SYS (memset_explicit
, void *, (void *__dest
, int __c
, size_t __n
));
365 _GL_CXXALIASWARN (memset_explicit
);
366 #elif defined GNULIB_POSIXCHECK
367 # undef memset_explicit
368 # if HAVE_RAW_DECL_MEMSET_EXPLICIT
369 _GL_WARN_ON_USE (memset_explicit
, "memset_explicit is unportable - "
370 "use gnulib module memset_explicit for portability");
374 /* Find the first occurrence of C in S. More efficient than
375 memchr(S,C,N), at the expense of undefined behavior if C does not
376 occur within N bytes. */
377 #if @GNULIB_RAWMEMCHR@
378 # if ! @HAVE_RAWMEMCHR@
379 _GL_FUNCDECL_SYS (rawmemchr
, void *, (void const *__s
, int __c_in
)
381 _GL_ARG_NONNULL ((1)));
383 /* On some systems, this function is defined as an overloaded function:
384 extern "C++" { const void * std::rawmemchr (const void *, int); }
385 extern "C++" { void * std::rawmemchr (void *, int); } */
386 _GL_CXXALIAS_SYS_CAST2 (rawmemchr
,
387 void *, (void const *__s
, int __c_in
),
388 void const *, (void const *__s
, int __c_in
));
389 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
390 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
391 || defined __clang__)
392 _GL_CXXALIASWARN1 (rawmemchr
, void *, (void *__s
, int __c_in
) throw ());
393 _GL_CXXALIASWARN1 (rawmemchr
, void const *,
394 (void const *__s
, int __c_in
) throw ());
396 _GL_CXXALIASWARN (rawmemchr
);
398 #elif defined GNULIB_POSIXCHECK
400 # if HAVE_RAW_DECL_RAWMEMCHR
401 _GL_WARN_ON_USE (rawmemchr
, "rawmemchr is unportable - "
402 "use gnulib module rawmemchr for portability");
406 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
409 _GL_FUNCDECL_SYS (stpcpy
, char *,
410 (char *restrict __dst
, char const *restrict __src
)
411 _GL_ARG_NONNULL ((1, 2)));
413 _GL_CXXALIAS_SYS (stpcpy
, char *,
414 (char *restrict __dst
, char const *restrict __src
));
415 _GL_CXXALIASWARN (stpcpy
);
416 #elif defined GNULIB_POSIXCHECK
418 # if HAVE_RAW_DECL_STPCPY
419 _GL_WARN_ON_USE (stpcpy
, "stpcpy is unportable - "
420 "use gnulib module stpcpy for portability");
424 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
425 last non-NUL byte written into DST. */
427 # if @REPLACE_STPNCPY@
428 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
430 # define stpncpy rpl_stpncpy
432 _GL_FUNCDECL_RPL (stpncpy
, char *,
433 (char *restrict __dst
, char const *restrict __src
,
435 _GL_ARG_NONNULL ((1, 2)));
436 _GL_CXXALIAS_RPL (stpncpy
, char *,
437 (char *restrict __dst
, char const *restrict __src
,
440 # if ! @HAVE_STPNCPY@
441 _GL_FUNCDECL_SYS (stpncpy
, char *,
442 (char *restrict __dst
, char const *restrict __src
,
444 _GL_ARG_NONNULL ((1, 2)));
446 _GL_CXXALIAS_SYS (stpncpy
, char *,
447 (char *restrict __dst
, char const *restrict __src
,
450 _GL_CXXALIASWARN (stpncpy
);
451 #elif defined GNULIB_POSIXCHECK
453 # if HAVE_RAW_DECL_STPNCPY
454 _GL_WARN_ON_USE (stpncpy
, "stpncpy is unportable - "
455 "use gnulib module stpncpy for portability");
459 #if defined GNULIB_POSIXCHECK
460 /* strchr() does not work with multibyte strings if the locale encoding is
461 GB18030 and the character to be searched is a digit. */
463 /* Assume strchr is always declared. */
464 _GL_WARN_ON_USE_CXX (strchr
,
465 const char *, char *, (const char *, int),
466 "strchr cannot work correctly on character strings "
467 "in some multibyte locales - "
468 "use mbschr if you care about internationalization");
471 /* Find the first occurrence of C in S or the final NUL byte. */
472 #if @GNULIB_STRCHRNUL@
473 # if @REPLACE_STRCHRNUL@
474 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
475 # define strchrnul rpl_strchrnul
477 _GL_FUNCDECL_RPL (strchrnul
, char *, (const char *__s
, int __c_in
)
479 _GL_ARG_NONNULL ((1)));
480 _GL_CXXALIAS_RPL (strchrnul
, char *,
481 (const char *str
, int ch
));
483 # if ! @HAVE_STRCHRNUL@
484 _GL_FUNCDECL_SYS (strchrnul
, char *, (char const *__s
, int __c_in
)
486 _GL_ARG_NONNULL ((1)));
488 /* On some systems, this function is defined as an overloaded function:
489 extern "C++" { const char * std::strchrnul (const char *, int); }
490 extern "C++" { char * std::strchrnul (char *, int); } */
491 _GL_CXXALIAS_SYS_CAST2 (strchrnul
,
492 char *, (char const *__s
, int __c_in
),
493 char const *, (char const *__s
, int __c_in
));
495 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
496 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
497 || defined __clang__)
498 _GL_CXXALIASWARN1 (strchrnul
, char *, (char *__s
, int __c_in
) throw ());
499 _GL_CXXALIASWARN1 (strchrnul
, char const *,
500 (char const *__s
, int __c_in
) throw ());
502 _GL_CXXALIASWARN (strchrnul
);
504 #elif defined GNULIB_POSIXCHECK
506 # if HAVE_RAW_DECL_STRCHRNUL
507 _GL_WARN_ON_USE (strchrnul
, "strchrnul is unportable - "
508 "use gnulib module strchrnul for portability");
512 /* Duplicate S, returning an identical malloc'd string. */
514 # if @REPLACE_STRDUP@
515 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
517 # define strdup rpl_strdup
519 _GL_FUNCDECL_RPL (strdup
, char *,
521 _GL_ARG_NONNULL ((1))
522 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
523 _GL_CXXALIAS_RPL (strdup
, char *, (char const *__s
));
524 # elif defined _WIN32 && !defined __CYGWIN__
525 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
527 # define strdup _strdup
529 _GL_CXXALIAS_MDA (strdup
, char *, (char const *__s
));
531 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
532 /* strdup exists as a function and as a macro. Get rid of the macro. */
535 # if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup
536 _GL_FUNCDECL_SYS (strdup
, char *,
538 _GL_ARG_NONNULL ((1))
539 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
541 _GL_CXXALIAS_SYS (strdup
, char *, (char const *__s
));
543 _GL_CXXALIASWARN (strdup
);
545 # if __GNUC__ >= 11 && !defined strdup
546 /* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */
547 _GL_FUNCDECL_SYS (strdup
, char *,
549 _GL_ARG_NONNULL ((1))
550 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
552 # if defined GNULIB_POSIXCHECK
554 # if HAVE_RAW_DECL_STRDUP
555 _GL_WARN_ON_USE (strdup
, "strdup is unportable - "
556 "use gnulib module strdup for portability");
558 # elif @GNULIB_MDA_STRDUP@
559 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
560 required. In C++ with GNULIB_NAMESPACE, avoid differences between
561 platforms by defining GNULIB_NAMESPACE::strdup always. */
562 # if defined _WIN32 && !defined __CYGWIN__
563 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
565 # define strdup _strdup
567 _GL_CXXALIAS_MDA (strdup
, char *, (char const *__s
));
569 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
572 _GL_CXXALIAS_SYS (strdup
, char *, (char const *__s
));
574 _GL_CXXALIASWARN (strdup
);
578 /* Append no more than N characters from SRC onto DEST. */
580 # if @REPLACE_STRNCAT@
581 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
583 # define strncat rpl_strncat
585 _GL_FUNCDECL_RPL (strncat
, char *,
586 (char *restrict dest
, const char *restrict src
, size_t n
)
587 _GL_ARG_NONNULL ((1, 2)));
588 _GL_CXXALIAS_RPL (strncat
, char *,
589 (char *restrict dest
, const char *restrict src
, size_t n
));
591 _GL_CXXALIAS_SYS (strncat
, char *,
592 (char *restrict dest
, const char *restrict src
, size_t n
));
595 _GL_CXXALIASWARN (strncat
);
597 #elif defined GNULIB_POSIXCHECK
599 # if HAVE_RAW_DECL_STRNCAT
600 _GL_WARN_ON_USE (strncat
, "strncat is unportable - "
601 "use gnulib module strncat for portability");
605 /* Return a newly allocated copy of at most N bytes of STRING. */
607 # if @REPLACE_STRNDUP@
608 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
610 # define strndup rpl_strndup
612 _GL_FUNCDECL_RPL (strndup
, char *,
613 (char const *__s
, size_t __n
)
614 _GL_ARG_NONNULL ((1))
615 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
616 _GL_CXXALIAS_RPL (strndup
, char *, (char const *__s
, size_t __n
));
618 # if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined strndup)
619 _GL_FUNCDECL_SYS (strndup
, char *,
620 (char const *__s
, size_t __n
)
621 _GL_ARG_NONNULL ((1))
622 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
624 _GL_CXXALIAS_SYS (strndup
, char *, (char const *__s
, size_t __n
));
626 _GL_CXXALIASWARN (strndup
);
628 # if __GNUC__ >= 11 && !defined strndup
629 /* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */
630 _GL_FUNCDECL_SYS (strndup
, char *,
631 (char const *__s
, size_t __n
)
632 _GL_ARG_NONNULL ((1))
633 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
);
635 # if defined GNULIB_POSIXCHECK
637 # if HAVE_RAW_DECL_STRNDUP
638 _GL_WARN_ON_USE (strndup
, "strndup is unportable - "
639 "use gnulib module strndup for portability");
644 /* Find the length (number of bytes) of STRING, but scan at most
645 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
648 # if @REPLACE_STRNLEN@
649 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
651 # define strnlen rpl_strnlen
653 _GL_FUNCDECL_RPL (strnlen
, size_t, (char const *__s
, size_t __maxlen
)
655 _GL_ARG_NONNULL ((1)));
656 _GL_CXXALIAS_RPL (strnlen
, size_t, (char const *__s
, size_t __maxlen
));
658 # if ! @HAVE_DECL_STRNLEN@
659 _GL_FUNCDECL_SYS (strnlen
, size_t, (char const *__s
, size_t __maxlen
)
661 _GL_ARG_NONNULL ((1)));
663 _GL_CXXALIAS_SYS (strnlen
, size_t, (char const *__s
, size_t __maxlen
));
665 _GL_CXXALIASWARN (strnlen
);
666 #elif defined GNULIB_POSIXCHECK
668 # if HAVE_RAW_DECL_STRNLEN
669 _GL_WARN_ON_USE (strnlen
, "strnlen is unportable - "
670 "use gnulib module strnlen for portability");
674 #if defined GNULIB_POSIXCHECK
675 /* strcspn() assumes the second argument is a list of single-byte characters.
676 Even in this simple case, it does not work with multibyte strings if the
677 locale encoding is GB18030 and one of the characters to be searched is a
680 /* Assume strcspn is always declared. */
681 _GL_WARN_ON_USE (strcspn
, "strcspn cannot work correctly on character strings "
682 "in multibyte locales - "
683 "use mbscspn if you care about internationalization");
686 /* Find the first occurrence in S of any character in ACCEPT. */
688 # if ! @HAVE_STRPBRK@
689 _GL_FUNCDECL_SYS (strpbrk
, char *, (char const *__s
, char const *__accept
)
691 _GL_ARG_NONNULL ((1, 2)));
693 /* On some systems, this function is defined as an overloaded function:
694 extern "C" { const char * strpbrk (const char *, const char *); }
695 extern "C++" { char * strpbrk (char *, const char *); } */
696 _GL_CXXALIAS_SYS_CAST2 (strpbrk
,
697 char *, (char const *__s
, char const *__accept
),
698 const char *, (char const *__s
, char const *__accept
));
699 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
700 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
701 || defined __clang__)
702 _GL_CXXALIASWARN1 (strpbrk
, char *, (char *__s
, char const *__accept
) throw ());
703 _GL_CXXALIASWARN1 (strpbrk
, char const *,
704 (char const *__s
, char const *__accept
) throw ());
705 # elif __GLIBC__ >= 2
706 _GL_CXXALIASWARN (strpbrk
);
708 # if defined GNULIB_POSIXCHECK
709 /* strpbrk() assumes the second argument is a list of single-byte characters.
710 Even in this simple case, it does not work with multibyte strings if the
711 locale encoding is GB18030 and one of the characters to be searched is a
714 _GL_WARN_ON_USE_CXX (strpbrk
,
715 const char *, char *, (const char *, const char *),
716 "strpbrk cannot work correctly on character strings "
717 "in multibyte locales - "
718 "use mbspbrk if you care about internationalization");
720 #elif defined GNULIB_POSIXCHECK
722 # if HAVE_RAW_DECL_STRPBRK
723 _GL_WARN_ON_USE_CXX (strpbrk
,
724 const char *, char *, (const char *, const char *),
725 "strpbrk is unportable - "
726 "use gnulib module strpbrk for portability");
730 #if defined GNULIB_POSIXCHECK
731 /* strspn() assumes the second argument is a list of single-byte characters.
732 Even in this simple case, it cannot work with multibyte strings. */
734 /* Assume strspn is always declared. */
735 _GL_WARN_ON_USE (strspn
, "strspn cannot work correctly on character strings "
736 "in multibyte locales - "
737 "use mbsspn if you care about internationalization");
740 #if defined GNULIB_POSIXCHECK
741 /* strrchr() does not work with multibyte strings if the locale encoding is
742 GB18030 and the character to be searched is a digit. */
744 /* Assume strrchr is always declared. */
745 _GL_WARN_ON_USE_CXX (strrchr
,
746 const char *, char *, (const char *, int),
747 "strrchr cannot work correctly on character strings "
748 "in some multibyte locales - "
749 "use mbsrchr if you care about internationalization");
752 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
753 If one is found, overwrite it with a NUL, and advance *STRINGP
754 to point to the next char after it. Otherwise, set *STRINGP to NULL.
755 If *STRINGP was already NULL, nothing happens.
756 Return the old value of *STRINGP.
758 This is a variant of strtok() that is multithread-safe and supports
761 Caveat: It modifies the original string.
762 Caveat: These functions cannot be used on constant strings.
763 Caveat: The identity of the delimiting character is lost.
764 Caveat: It doesn't work with multibyte strings unless all of the delimiter
765 characters are ASCII characters < 0x30.
767 See also strtok_r(). */
770 _GL_FUNCDECL_SYS (strsep
, char *,
771 (char **restrict __stringp
, char const *restrict __delim
)
772 _GL_ARG_NONNULL ((1, 2)));
774 _GL_CXXALIAS_SYS (strsep
, char *,
775 (char **restrict __stringp
, char const *restrict __delim
));
776 _GL_CXXALIASWARN (strsep
);
777 # if defined GNULIB_POSIXCHECK
779 _GL_WARN_ON_USE (strsep
, "strsep cannot work correctly on character strings "
780 "in multibyte locales - "
781 "use mbssep if you care about internationalization");
783 #elif defined GNULIB_POSIXCHECK
785 # if HAVE_RAW_DECL_STRSEP
786 _GL_WARN_ON_USE (strsep
, "strsep is unportable - "
787 "use gnulib module strsep for portability");
792 # if @REPLACE_STRSTR@
793 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
794 # define strstr rpl_strstr
796 _GL_FUNCDECL_RPL (strstr
, char *, (const char *haystack
, const char *needle
)
798 _GL_ARG_NONNULL ((1, 2)));
799 _GL_CXXALIAS_RPL (strstr
, char *, (const char *haystack
, const char *needle
));
801 /* On some systems, this function is defined as an overloaded function:
802 extern "C++" { const char * strstr (const char *, const char *); }
803 extern "C++" { char * strstr (char *, const char *); } */
804 _GL_CXXALIAS_SYS_CAST2 (strstr
,
805 char *, (const char *haystack
, const char *needle
),
806 const char *, (const char *haystack
, const char *needle
));
808 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
809 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
810 || defined __clang__)
811 _GL_CXXALIASWARN1 (strstr
, char *,
812 (char *haystack
, const char *needle
) throw ());
813 _GL_CXXALIASWARN1 (strstr
, const char *,
814 (const char *haystack
, const char *needle
) throw ());
815 # elif __GLIBC__ >= 2
816 _GL_CXXALIASWARN (strstr
);
818 #elif defined GNULIB_POSIXCHECK
819 /* strstr() does not work with multibyte strings if the locale encoding is
820 different from UTF-8:
821 POSIX says that it operates on "strings", and "string" in POSIX is defined
822 as a sequence of bytes, not of characters. */
824 /* Assume strstr is always declared. */
825 _GL_WARN_ON_USE (strstr
, "strstr is quadratic on many systems, and cannot "
826 "work correctly on character strings in most "
827 "multibyte locales - "
828 "use mbsstr if you care about internationalization, "
829 "or use strstr if you care about speed");
832 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
834 #if @GNULIB_STRCASESTR@
835 # if @REPLACE_STRCASESTR@
836 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
837 # define strcasestr rpl_strcasestr
839 _GL_FUNCDECL_RPL (strcasestr
, char *,
840 (const char *haystack
, const char *needle
)
842 _GL_ARG_NONNULL ((1, 2)));
843 _GL_CXXALIAS_RPL (strcasestr
, char *,
844 (const char *haystack
, const char *needle
));
846 # if ! @HAVE_STRCASESTR@
847 _GL_FUNCDECL_SYS (strcasestr
, char *,
848 (const char *haystack
, const char *needle
)
850 _GL_ARG_NONNULL ((1, 2)));
852 /* On some systems, this function is defined as an overloaded function:
853 extern "C++" { const char * strcasestr (const char *, const char *); }
854 extern "C++" { char * strcasestr (char *, const char *); } */
855 _GL_CXXALIAS_SYS_CAST2 (strcasestr
,
856 char *, (const char *haystack
, const char *needle
),
857 const char *, (const char *haystack
, const char *needle
));
859 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
860 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
861 || defined __clang__)
862 _GL_CXXALIASWARN1 (strcasestr
, char *,
863 (char *haystack
, const char *needle
) throw ());
864 _GL_CXXALIASWARN1 (strcasestr
, const char *,
865 (const char *haystack
, const char *needle
) throw ());
867 _GL_CXXALIASWARN (strcasestr
);
869 #elif defined GNULIB_POSIXCHECK
870 /* strcasestr() does not work with multibyte strings:
871 It is a glibc extension, and glibc implements it only for unibyte
874 # if HAVE_RAW_DECL_STRCASESTR
875 _GL_WARN_ON_USE (strcasestr
, "strcasestr does work correctly on character "
876 "strings in multibyte locales - "
877 "use mbscasestr if you care about "
878 "internationalization, or use c-strcasestr if you want "
879 "a locale independent function");
883 /* Parse S into tokens separated by characters in DELIM.
884 If S is NULL, the saved pointer in SAVE_PTR is used as
885 the next starting point. For example:
886 char s[] = "-abc-=-def";
888 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
889 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
890 x = strtok_r(NULL, "=", &sp); // x = NULL
893 This is a variant of strtok() that is multithread-safe.
895 For the POSIX documentation for this function, see:
896 https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html
898 Caveat: It modifies the original string.
899 Caveat: These functions cannot be used on constant strings.
900 Caveat: The identity of the delimiting character is lost.
901 Caveat: It doesn't work with multibyte strings unless all of the delimiter
902 characters are ASCII characters < 0x30.
904 See also strsep(). */
905 #if @GNULIB_STRTOK_R@
906 # if @REPLACE_STRTOK_R@
907 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
909 # define strtok_r rpl_strtok_r
911 _GL_FUNCDECL_RPL (strtok_r
, char *,
912 (char *restrict s
, char const *restrict delim
,
913 char **restrict save_ptr
)
914 _GL_ARG_NONNULL ((2, 3)));
915 _GL_CXXALIAS_RPL (strtok_r
, char *,
916 (char *restrict s
, char const *restrict delim
,
917 char **restrict save_ptr
));
919 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
922 # if ! @HAVE_DECL_STRTOK_R@
923 _GL_FUNCDECL_SYS (strtok_r
, char *,
924 (char *restrict s
, char const *restrict delim
,
925 char **restrict save_ptr
)
926 _GL_ARG_NONNULL ((2, 3)));
928 _GL_CXXALIAS_SYS (strtok_r
, char *,
929 (char *restrict s
, char const *restrict delim
,
930 char **restrict save_ptr
));
932 _GL_CXXALIASWARN (strtok_r
);
933 # if defined GNULIB_POSIXCHECK
934 _GL_WARN_ON_USE (strtok_r
, "strtok_r cannot work correctly on character "
935 "strings in multibyte locales - "
936 "use mbstok_r if you care about internationalization");
938 #elif defined GNULIB_POSIXCHECK
940 # if HAVE_RAW_DECL_STRTOK_R
941 _GL_WARN_ON_USE (strtok_r
, "strtok_r is unportable - "
942 "use gnulib module strtok_r for portability");
947 /* The following functions are not specified by POSIX. They are gnulib
951 /* Return the number of multibyte characters in the character string STRING.
952 This considers multibyte characters, unlike strlen, which counts bytes. */
953 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
956 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
957 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
958 # define mbslen rpl_mbslen
960 _GL_FUNCDECL_RPL (mbslen
, size_t, (const char *string
)
962 _GL_ARG_NONNULL ((1)));
963 _GL_CXXALIAS_RPL (mbslen
, size_t, (const char *string
));
965 _GL_FUNCDECL_SYS (mbslen
, size_t, (const char *string
)
967 _GL_ARG_NONNULL ((1)));
968 _GL_CXXALIAS_SYS (mbslen
, size_t, (const char *string
));
971 _GL_CXXALIASWARN (mbslen
);
976 /* Return the number of multibyte characters in the character string starting
977 at STRING and ending at STRING + LEN. */
978 _GL_EXTERN_C
size_t mbsnlen (const char *string
, size_t len
)
980 _GL_ARG_NONNULL ((1));
984 /* Locate the first single-byte character C in the character string STRING,
985 and return a pointer to it. Return NULL if C is not found in STRING.
986 Unlike strchr(), this function works correctly in multibyte locales with
987 encodings such as GB18030. */
989 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
990 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
992 _GL_FUNCDECL_RPL (mbschr
, char *, (const char *string
, int c
)
994 _GL_ARG_NONNULL ((1)));
995 _GL_CXXALIAS_RPL (mbschr
, char *, (const char *string
, int c
));
997 _GL_FUNCDECL_SYS (mbschr
, char *, (const char *string
, int c
)
999 _GL_ARG_NONNULL ((1)));
1000 _GL_CXXALIAS_SYS (mbschr
, char *, (const char *string
, int c
));
1002 _GL_CXXALIASWARN (mbschr
);
1005 #if @GNULIB_MBSRCHR@
1006 /* Locate the last single-byte character C in the character string STRING,
1007 and return a pointer to it. Return NULL if C is not found in STRING.
1008 Unlike strrchr(), this function works correctly in multibyte locales with
1009 encodings such as GB18030. */
1010 # if defined __hpux || defined __INTERIX
1011 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1012 # define mbsrchr rpl_mbsrchr /* avoid collision with system function */
1014 _GL_FUNCDECL_RPL (mbsrchr
, char *, (const char *string
, int c
)
1016 _GL_ARG_NONNULL ((1)));
1017 _GL_CXXALIAS_RPL (mbsrchr
, char *, (const char *string
, int c
));
1019 _GL_FUNCDECL_SYS (mbsrchr
, char *, (const char *string
, int c
)
1021 _GL_ARG_NONNULL ((1)));
1022 _GL_CXXALIAS_SYS (mbsrchr
, char *, (const char *string
, int c
));
1024 _GL_CXXALIASWARN (mbsrchr
);
1028 /* Find the first occurrence of the character string NEEDLE in the character
1029 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
1030 Unlike strstr(), this function works correctly in multibyte locales with
1031 encodings different from UTF-8. */
1032 _GL_EXTERN_C
char * mbsstr (const char *haystack
, const char *needle
)
1034 _GL_ARG_NONNULL ((1, 2));
1037 #if @GNULIB_MBSCASECMP@
1038 /* Compare the character strings S1 and S2, ignoring case, returning less than,
1039 equal to or greater than zero if S1 is lexicographically less than, equal to
1041 Note: This function may, in multibyte locales, return 0 for strings of
1043 Unlike strcasecmp(), this function works correctly in multibyte locales. */
1044 _GL_EXTERN_C
int mbscasecmp (const char *s1
, const char *s2
)
1046 _GL_ARG_NONNULL ((1, 2));
1049 #if @GNULIB_MBSNCASECMP@
1050 /* Compare the initial segment of the character string S1 consisting of at most
1051 N characters with the initial segment of the character string S2 consisting
1052 of at most N characters, ignoring case, returning less than, equal to or
1053 greater than zero if the initial segment of S1 is lexicographically less
1054 than, equal to or greater than the initial segment of S2.
1055 Note: This function may, in multibyte locales, return 0 for initial segments
1056 of different lengths!
1057 Unlike strncasecmp(), this function works correctly in multibyte locales.
1058 But beware that N is not a byte count but a character count! */
1059 _GL_EXTERN_C
int mbsncasecmp (const char *s1
, const char *s2
, size_t n
)
1061 _GL_ARG_NONNULL ((1, 2));
1064 #if @GNULIB_MBSPCASECMP@
1065 /* Compare the initial segment of the character string STRING consisting of
1066 at most mbslen (PREFIX) characters with the character string PREFIX,
1067 ignoring case. If the two match, return a pointer to the first byte
1068 after this prefix in STRING. Otherwise, return NULL.
1069 Note: This function may, in multibyte locales, return non-NULL if STRING
1070 is of smaller length than PREFIX!
1071 Unlike strncasecmp(), this function works correctly in multibyte
1073 _GL_EXTERN_C
char * mbspcasecmp (const char *string
, const char *prefix
)
1075 _GL_ARG_NONNULL ((1, 2));
1078 #if @GNULIB_MBSCASESTR@
1079 /* Find the first occurrence of the character string NEEDLE in the character
1080 string HAYSTACK, using case-insensitive comparison.
1081 Note: This function may, in multibyte locales, return success even if
1082 strlen (haystack) < strlen (needle) !
1083 Unlike strcasestr(), this function works correctly in multibyte locales. */
1084 _GL_EXTERN_C
char * mbscasestr (const char *haystack
, const char *needle
)
1086 _GL_ARG_NONNULL ((1, 2));
1089 #if @GNULIB_MBSCSPN@
1090 /* Find the first occurrence in the character string STRING of any character
1091 in the character string ACCEPT. Return the number of bytes from the
1092 beginning of the string to this occurrence, or to the end of the string
1094 Unlike strcspn(), this function works correctly in multibyte locales. */
1095 _GL_EXTERN_C
size_t mbscspn (const char *string
, const char *accept
)
1097 _GL_ARG_NONNULL ((1, 2));
1100 #if @GNULIB_MBSPBRK@
1101 /* Find the first occurrence in the character string STRING of any character
1102 in the character string ACCEPT. Return the pointer to it, or NULL if none
1104 Unlike strpbrk(), this function works correctly in multibyte locales. */
1106 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1107 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1109 _GL_FUNCDECL_RPL (mbspbrk
, char *, (const char *string
, const char *accept
)
1111 _GL_ARG_NONNULL ((1, 2)));
1112 _GL_CXXALIAS_RPL (mbspbrk
, char *, (const char *string
, const char *accept
));
1114 _GL_FUNCDECL_SYS (mbspbrk
, char *, (const char *string
, const char *accept
)
1116 _GL_ARG_NONNULL ((1, 2)));
1117 _GL_CXXALIAS_SYS (mbspbrk
, char *, (const char *string
, const char *accept
));
1119 _GL_CXXALIASWARN (mbspbrk
);
1123 /* Find the first occurrence in the character string STRING of any character
1124 not in the character string REJECT. Return the number of bytes from the
1125 beginning of the string to this occurrence, or to the end of the string
1127 Unlike strspn(), this function works correctly in multibyte locales. */
1128 _GL_EXTERN_C
size_t mbsspn (const char *string
, const char *reject
)
1130 _GL_ARG_NONNULL ((1, 2));
1134 /* Search the next delimiter (multibyte character listed in the character
1135 string DELIM) starting at the character string *STRINGP.
1136 If one is found, overwrite it with a NUL, and advance *STRINGP to point
1137 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
1138 If *STRINGP was already NULL, nothing happens.
1139 Return the old value of *STRINGP.
1141 This is a variant of mbstok_r() that supports empty fields.
1143 Caveat: It modifies the original string.
1144 Caveat: These functions cannot be used on constant strings.
1145 Caveat: The identity of the delimiting character is lost.
1147 See also mbstok_r(). */
1148 _GL_EXTERN_C
char * mbssep (char **stringp
, const char *delim
)
1149 _GL_ARG_NONNULL ((1, 2));
1152 #if @GNULIB_MBSTOK_R@
1153 /* Parse the character string STRING into tokens separated by characters in
1154 the character string DELIM.
1155 If STRING is NULL, the saved pointer in SAVE_PTR is used as
1156 the next starting point. For example:
1157 char s[] = "-abc-=-def";
1159 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1160 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1161 x = mbstok_r(NULL, "=", &sp); // x = NULL
1162 // s = "abc\0-def\0"
1164 Caveat: It modifies the original string.
1165 Caveat: These functions cannot be used on constant strings.
1166 Caveat: The identity of the delimiting character is lost.
1168 See also mbssep(). */
1169 _GL_EXTERN_C
char * mbstok_r (char *restrict string
, const char *delim
,
1171 _GL_ARG_NONNULL ((2, 3));
1174 /* Map any int, typically from errno, into an error message. */
1175 #if @GNULIB_STRERROR@
1176 # if @REPLACE_STRERROR@
1177 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1179 # define strerror rpl_strerror
1181 _GL_FUNCDECL_RPL (strerror
, char *, (int));
1182 _GL_CXXALIAS_RPL (strerror
, char *, (int));
1184 _GL_CXXALIAS_SYS (strerror
, char *, (int));
1187 _GL_CXXALIASWARN (strerror
);
1189 #elif defined GNULIB_POSIXCHECK
1191 /* Assume strerror is always declared. */
1192 _GL_WARN_ON_USE (strerror
, "strerror is unportable - "
1193 "use gnulib module strerror to guarantee non-NULL result");
1196 /* Map any int, typically from errno, into an error message. Multithread-safe.
1197 Uses the POSIX declaration, not the glibc declaration. */
1198 #if @GNULIB_STRERROR_R@
1199 # if @REPLACE_STRERROR_R@
1200 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1202 # define strerror_r rpl_strerror_r
1204 _GL_FUNCDECL_RPL (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
)
1205 _GL_ARG_NONNULL ((2)));
1206 _GL_CXXALIAS_RPL (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
));
1208 # if !@HAVE_DECL_STRERROR_R@
1209 _GL_FUNCDECL_SYS (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
)
1210 _GL_ARG_NONNULL ((2)));
1212 _GL_CXXALIAS_SYS (strerror_r
, int, (int errnum
, char *buf
, size_t buflen
));
1214 # if @HAVE_DECL_STRERROR_R@
1215 _GL_CXXALIASWARN (strerror_r
);
1217 #elif defined GNULIB_POSIXCHECK
1219 # if HAVE_RAW_DECL_STRERROR_R
1220 _GL_WARN_ON_USE (strerror_r
, "strerror_r is unportable - "
1221 "use gnulib module strerror_r-posix for portability");
1225 /* Return the name of the system error code ERRNUM. */
1226 #if @GNULIB_STRERRORNAME_NP@
1227 # if @REPLACE_STRERRORNAME_NP@
1228 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1229 # undef strerrorname_np
1230 # define strerrorname_np rpl_strerrorname_np
1232 _GL_FUNCDECL_RPL (strerrorname_np
, const char *, (int errnum
));
1233 _GL_CXXALIAS_RPL (strerrorname_np
, const char *, (int errnum
));
1235 # if !@HAVE_STRERRORNAME_NP@
1236 _GL_FUNCDECL_SYS (strerrorname_np
, const char *, (int errnum
));
1238 _GL_CXXALIAS_SYS (strerrorname_np
, const char *, (int errnum
));
1240 _GL_CXXALIASWARN (strerrorname_np
);
1241 #elif defined GNULIB_POSIXCHECK
1242 # undef strerrorname_np
1243 # if HAVE_RAW_DECL_STRERRORNAME_NP
1244 _GL_WARN_ON_USE (strerrorname_np
, "strerrorname_np is unportable - "
1245 "use gnulib module strerrorname_np for portability");
1249 /* Return an abbreviation string for the signal number SIG. */
1250 #if @GNULIB_SIGABBREV_NP@
1251 # if ! @HAVE_SIGABBREV_NP@
1252 _GL_FUNCDECL_SYS (sigabbrev_np
, const char *, (int sig
));
1254 _GL_CXXALIAS_SYS (sigabbrev_np
, const char *, (int sig
));
1255 _GL_CXXALIASWARN (sigabbrev_np
);
1256 #elif defined GNULIB_POSIXCHECK
1257 # undef sigabbrev_np
1258 # if HAVE_RAW_DECL_SIGABBREV_NP
1259 _GL_WARN_ON_USE (sigabbrev_np
, "sigabbrev_np is unportable - "
1260 "use gnulib module sigabbrev_np for portability");
1264 /* Return an English description string for the signal number SIG. */
1265 #if @GNULIB_SIGDESCR_NP@
1266 # if ! @HAVE_SIGDESCR_NP@
1267 _GL_FUNCDECL_SYS (sigdescr_np
, const char *, (int sig
));
1269 _GL_CXXALIAS_SYS (sigdescr_np
, const char *, (int sig
));
1270 _GL_CXXALIASWARN (sigdescr_np
);
1271 #elif defined GNULIB_POSIXCHECK
1273 # if HAVE_RAW_DECL_SIGDESCR_NP
1274 _GL_WARN_ON_USE (sigdescr_np
, "sigdescr_np is unportable - "
1275 "use gnulib module sigdescr_np for portability");
1279 #if @GNULIB_STRSIGNAL@
1280 # if @REPLACE_STRSIGNAL@
1281 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1282 # define strsignal rpl_strsignal
1284 _GL_FUNCDECL_RPL (strsignal
, char *, (int __sig
));
1285 _GL_CXXALIAS_RPL (strsignal
, char *, (int __sig
));
1287 # if ! @HAVE_DECL_STRSIGNAL@
1288 _GL_FUNCDECL_SYS (strsignal
, char *, (int __sig
));
1290 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
1292 _GL_CXXALIAS_SYS_CAST (strsignal
, char *, (int __sig
));
1294 _GL_CXXALIASWARN (strsignal
);
1295 #elif defined GNULIB_POSIXCHECK
1297 # if HAVE_RAW_DECL_STRSIGNAL
1298 _GL_WARN_ON_USE (strsignal
, "strsignal is unportable - "
1299 "use gnulib module strsignal for portability");
1303 #if @GNULIB_STRVERSCMP@
1304 # if !@HAVE_STRVERSCMP@
1305 _GL_FUNCDECL_SYS (strverscmp
, int, (const char *, const char *)
1307 _GL_ARG_NONNULL ((1, 2)));
1309 _GL_CXXALIAS_SYS (strverscmp
, int, (const char *, const char *));
1310 _GL_CXXALIASWARN (strverscmp
);
1311 #elif defined GNULIB_POSIXCHECK
1313 # if HAVE_RAW_DECL_STRVERSCMP
1314 _GL_WARN_ON_USE (strverscmp
, "strverscmp is unportable - "
1315 "use gnulib module strverscmp for portability");
1320 #endif /* _@GUARD_PREFIX@_STRING_H */
1321 #endif /* _@GUARD_PREFIX@_STRING_H */