Merge pull request #2046 from RincewindsHat/fix/format_string
[monitoring-plugins.git] / gl / string.in.h
blob44ec2e7ecdb5070ddf684d739f298e37cceedb17
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/>. */
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
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@
32 #else
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,
49 HAVE_RAW_DECL_*. */
50 #if !_GL_CONFIG_H_INCLUDED
51 #error "Please include config.h first."
52 #endif
54 /* NetBSD 5.0 mis-defines NULL. */
55 #include <stddef.h>
57 /* MirBSD defines mbslen as a macro. */
58 #if @GNULIB_MBSLEN@ && defined __MirBSD__
59 # include <wchar.h>
60 #endif
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__
66 # include <unistd.h>
67 #endif
69 /* AIX 7.2 and Android 13 declare ffsl and ffsll in <strings.h>, not in
70 <string.h>. */
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__
75 # include <strings.h>
76 #endif
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
80 function F. */
81 #ifndef _GL_ATTRIBUTE_DEALLOC
82 # if __GNUC__ >= 11
83 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
84 # else
85 # define _GL_ATTRIBUTE_DEALLOC(f, i)
86 # endif
87 #endif
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)
97 # else
98 # define _GL_ATTRIBUTE_DEALLOC_FREE \
99 _GL_ATTRIBUTE_DEALLOC (free, 1)
100 # endif
101 #endif
103 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
104 allocated memory. */
105 /* Applies to: functions. */
106 #ifndef _GL_ATTRIBUTE_MALLOC
107 # if __GNUC__ >= 3 || defined __clang__
108 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
109 # else
110 # define _GL_ATTRIBUTE_MALLOC
111 # endif
112 #endif
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)
121 # else
122 # define _GL_ATTRIBUTE_NOTHROW throw ()
123 # endif
124 # else
125 # define _GL_ATTRIBUTE_NOTHROW
126 # endif
127 # else
128 # if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__
129 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
130 # else
131 # define _GL_ATTRIBUTE_NOTHROW
132 # endif
133 # endif
134 #endif
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__))
141 # else
142 # define _GL_ATTRIBUTE_PURE /* empty */
143 # endif
144 #endif
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;
160 # else
161 _GL_EXTERN_C void rpl_free (void *);
162 # endif
163 # undef _GL_ATTRIBUTE_DEALLOC_FREE
164 # define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
165 # else
166 # if defined _MSC_VER && !defined free
167 _GL_EXTERN_C
168 # if defined _DLL
169 __declspec (dllimport)
170 # endif
171 void __cdecl free (void *);
172 # else
173 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
174 _GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
175 # else
176 _GL_EXTERN_C void free (void *);
177 # endif
178 # endif
179 # endif
180 #else
181 # if defined _MSC_VER && !defined free
182 _GL_EXTERN_C
183 # if defined _DLL
184 __declspec (dllimport)
185 # endif
186 void __cdecl free (void *);
187 # else
188 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
189 _GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
190 # else
191 _GL_EXTERN_C void free (void *);
192 # endif
193 # endif
194 #endif
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)));
202 # endif
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");
210 # endif
211 #endif
213 /* Find the index of the least-significant set bit. */
214 #if @GNULIB_FFSL@
215 # if !@HAVE_FFSL@
216 _GL_FUNCDECL_SYS (ffsl, int, (long int i));
217 # endif
218 _GL_CXXALIAS_SYS (ffsl, int, (long int i));
219 _GL_CXXALIASWARN (ffsl);
220 #elif defined GNULIB_POSIXCHECK
221 # undef ffsl
222 # if HAVE_RAW_DECL_FFSL
223 _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
224 # endif
225 #endif
228 /* Find the index of the least-significant set bit. */
229 #if @GNULIB_FFSLL@
230 # if @REPLACE_FFSLL@
231 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
232 # define ffsll rpl_ffsll
233 # endif
234 _GL_FUNCDECL_RPL (ffsll, int, (long long int i));
235 _GL_CXXALIAS_RPL (ffsll, int, (long long int i));
236 # else
237 # if !@HAVE_FFSLL@
238 _GL_FUNCDECL_SYS (ffsll, int, (long long int i));
239 # endif
240 _GL_CXXALIAS_SYS (ffsll, int, (long long int i));
241 # endif
242 _GL_CXXALIASWARN (ffsll);
243 #elif defined GNULIB_POSIXCHECK
244 # undef ffsll
245 # if HAVE_RAW_DECL_FFSLL
246 _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
247 # endif
248 #endif
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)
257 # undef memccpy
258 # define memccpy _memccpy
259 # endif
260 _GL_CXXALIAS_MDA (memccpy, void *,
261 (void *dest, const void *src, int c, size_t n));
262 # else
263 _GL_CXXALIAS_SYS (memccpy, void *,
264 (void *dest, const void *src, int c, size_t n));
265 # endif
266 _GL_CXXALIASWARN (memccpy);
267 #endif
270 /* Return the first instance of C within N bytes of S, or NULL. */
271 #if @GNULIB_MEMCHR@
272 # if @REPLACE_MEMCHR@
273 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
274 # undef memchr
275 # define memchr rpl_memchr
276 # endif
277 _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
278 _GL_ATTRIBUTE_PURE
279 _GL_ARG_NONNULL ((1)));
280 _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
281 # else
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));
288 # endif
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);
300 # endif
301 #elif defined GNULIB_POSIXCHECK
302 # undef memchr
303 /* Assume memchr is always declared. */
304 _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
305 "use gnulib module memchr for portability" );
306 #endif
308 /* Return the first occurrence of NEEDLE in HAYSTACK. */
309 #if @GNULIB_MEMMEM@
310 # if @REPLACE_MEMMEM@
311 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
312 # define memmem rpl_memmem
313 # endif
314 _GL_FUNCDECL_RPL (memmem, void *,
315 (void const *__haystack, size_t __haystack_len,
316 void const *__needle, size_t __needle_len)
317 _GL_ATTRIBUTE_PURE
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));
322 # else
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)
327 _GL_ATTRIBUTE_PURE
328 _GL_ARG_NONNULL ((1, 3)));
329 # endif
330 _GL_CXXALIAS_SYS (memmem, void *,
331 (void const *__haystack, size_t __haystack_len,
332 void const *__needle, size_t __needle_len));
333 # endif
334 _GL_CXXALIASWARN (memmem);
335 #elif defined GNULIB_POSIXCHECK
336 # undef memmem
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" );
341 # endif
342 #endif
344 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
345 last written byte. */
346 #if @GNULIB_MEMPCPY@
347 # if @REPLACE_MEMPCPY@
348 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
349 # undef mempcpy
350 # define mempcpy rpl_mempcpy
351 # endif
352 _GL_FUNCDECL_RPL (mempcpy, void *,
353 (void *restrict __dest, void const *restrict __src,
354 size_t __n)
355 _GL_ARG_NONNULL ((1, 2)));
356 _GL_CXXALIAS_RPL (mempcpy, void *,
357 (void *restrict __dest, void const *restrict __src,
358 size_t __n));
359 # else
360 # if !@HAVE_MEMPCPY@
361 _GL_FUNCDECL_SYS (mempcpy, void *,
362 (void *restrict __dest, void const *restrict __src,
363 size_t __n)
364 _GL_ARG_NONNULL ((1, 2)));
365 # endif
366 _GL_CXXALIAS_SYS (mempcpy, void *,
367 (void *restrict __dest, void const *restrict __src,
368 size_t __n));
369 # endif
370 # if __GLIBC__ >= 2
371 _GL_CXXALIASWARN (mempcpy);
372 # endif
373 #elif defined GNULIB_POSIXCHECK
374 # undef mempcpy
375 # if HAVE_RAW_DECL_MEMPCPY
376 _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
377 "use gnulib module mempcpy for portability");
378 # endif
379 #endif
381 /* Search backwards through a block for a byte (specified as an int). */
382 #if @GNULIB_MEMRCHR@
383 # if ! @HAVE_DECL_MEMRCHR@
384 _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
385 _GL_ATTRIBUTE_PURE
386 _GL_ARG_NONNULL ((1)));
387 # endif
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);
405 # endif
406 #elif defined GNULIB_POSIXCHECK
407 # undef memrchr
408 # if HAVE_RAW_DECL_MEMRCHR
409 _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
410 "use gnulib module memrchr for portability");
411 # endif
412 #endif
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
421 # endif
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));
425 # else
426 # if !@HAVE_MEMSET_EXPLICIT@
427 _GL_FUNCDECL_SYS (memset_explicit, void *,
428 (void *__dest, int __c, size_t __n) _GL_ARG_NONNULL ((1)));
429 # endif
430 _GL_CXXALIAS_SYS (memset_explicit, void *, (void *__dest, int __c, size_t __n));
431 # endif
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");
438 # endif
439 #endif
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)
447 _GL_ATTRIBUTE_PURE
448 _GL_ARG_NONNULL ((1)));
449 # endif
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);
465 # else
466 _GL_CXXALIASWARN (rawmemchr);
467 # endif
468 #elif defined GNULIB_POSIXCHECK
469 # undef rawmemchr
470 # if HAVE_RAW_DECL_RAWMEMCHR
471 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
472 "use gnulib module rawmemchr for portability");
473 # endif
474 #endif
476 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
477 #if @GNULIB_STPCPY@
478 # if @REPLACE_STPCPY@
479 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
480 # undef stpcpy
481 # define stpcpy rpl_stpcpy
482 # endif
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));
488 # else
489 # if !@HAVE_STPCPY@
490 _GL_FUNCDECL_SYS (stpcpy, char *,
491 (char *restrict __dst, char const *restrict __src)
492 _GL_ARG_NONNULL ((1, 2)));
493 # endif
494 _GL_CXXALIAS_SYS (stpcpy, char *,
495 (char *restrict __dst, char const *restrict __src));
496 # endif
497 # if __GLIBC__ >= 2
498 _GL_CXXALIASWARN (stpcpy);
499 # endif
500 #elif defined GNULIB_POSIXCHECK
501 # undef stpcpy
502 # if HAVE_RAW_DECL_STPCPY
503 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
504 "use gnulib module stpcpy for portability");
505 # endif
506 #endif
508 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
509 last non-NUL byte written into DST. */
510 #if @GNULIB_STPNCPY@
511 # if @REPLACE_STPNCPY@
512 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
513 # undef stpncpy
514 # define stpncpy rpl_stpncpy
515 # endif
516 _GL_FUNCDECL_RPL (stpncpy, char *,
517 (char *restrict __dst, char const *restrict __src,
518 size_t __n)
519 _GL_ARG_NONNULL ((1, 2)));
520 _GL_CXXALIAS_RPL (stpncpy, char *,
521 (char *restrict __dst, char const *restrict __src,
522 size_t __n));
523 # else
524 # if ! @HAVE_STPNCPY@
525 _GL_FUNCDECL_SYS (stpncpy, char *,
526 (char *restrict __dst, char const *restrict __src,
527 size_t __n)
528 _GL_ARG_NONNULL ((1, 2)));
529 # endif
530 _GL_CXXALIAS_SYS (stpncpy, char *,
531 (char *restrict __dst, char const *restrict __src,
532 size_t __n));
533 # endif
534 # if __GLIBC__ >= 2
535 _GL_CXXALIASWARN (stpncpy);
536 # endif
537 #elif defined GNULIB_POSIXCHECK
538 # undef stpncpy
539 # if HAVE_RAW_DECL_STPNCPY
540 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
541 "use gnulib module stpncpy for portability");
542 # endif
543 #endif
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. */
548 # undef strchr
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");
555 #endif
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
562 # endif
563 _GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in)
564 _GL_ATTRIBUTE_PURE
565 _GL_ARG_NONNULL ((1)));
566 _GL_CXXALIAS_RPL (strchrnul, char *,
567 (const char *str, int ch));
568 # else
569 # if ! @HAVE_STRCHRNUL@
570 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
571 _GL_ATTRIBUTE_PURE
572 _GL_ARG_NONNULL ((1)));
573 # endif
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));
580 # endif
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);
592 # endif
593 #elif defined GNULIB_POSIXCHECK
594 # undef strchrnul
595 # if HAVE_RAW_DECL_STRCHRNUL
596 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
597 "use gnulib module strchrnul for portability");
598 # endif
599 #endif
601 /* Duplicate S, returning an identical malloc'd string. */
602 #if @GNULIB_STRDUP@
603 # if @REPLACE_STRDUP@
604 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
605 # undef strdup
606 # define strdup rpl_strdup
607 # endif
608 _GL_FUNCDECL_RPL (strdup, char *,
609 (char const *__s)
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)
615 # undef strdup
616 # define strdup _strdup
617 # endif
618 _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
619 # else
620 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
621 /* strdup exists as a function and as a macro. Get rid of the macro. */
622 # undef strdup
623 # endif
624 # if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup
625 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
626 _GL_FUNCDECL_SYS (strdup, char *,
627 (char const *__s)
628 _GL_ATTRIBUTE_NOTHROW
629 _GL_ARG_NONNULL ((1))
630 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
631 # else
632 _GL_FUNCDECL_SYS (strdup, char *,
633 (char const *__s)
634 _GL_ARG_NONNULL ((1))
635 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
636 # endif
637 # endif
638 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
639 # endif
640 _GL_CXXALIASWARN (strdup);
641 #else
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 *,
646 (char const *__s)
647 _GL_ATTRIBUTE_NOTHROW
648 _GL_ARG_NONNULL ((1))
649 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
650 # else
651 _GL_FUNCDECL_SYS (strdup, char *,
652 (char const *__s)
653 _GL_ARG_NONNULL ((1))
654 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
655 # endif
656 # endif
657 # if defined GNULIB_POSIXCHECK
658 # undef strdup
659 # if HAVE_RAW_DECL_STRDUP
660 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
661 "use gnulib module strdup for portability");
662 # endif
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)
669 # undef strdup
670 # define strdup _strdup
671 # endif
672 _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
673 # else
674 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
675 # undef strdup
676 # endif
677 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
678 # endif
679 _GL_CXXALIASWARN (strdup);
680 # endif
681 #endif
683 /* Append no more than N characters from SRC onto DEST. */
684 #if @GNULIB_STRNCAT@
685 # if @REPLACE_STRNCAT@
686 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
687 # undef strncat
688 # define strncat rpl_strncat
689 # endif
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));
695 # else
696 _GL_CXXALIAS_SYS (strncat, char *,
697 (char *restrict dest, const char *restrict src, size_t n));
698 # endif
699 # if __GLIBC__ >= 2
700 _GL_CXXALIASWARN (strncat);
701 # endif
702 #elif defined GNULIB_POSIXCHECK
703 # undef strncat
704 # if HAVE_RAW_DECL_STRNCAT
705 _GL_WARN_ON_USE (strncat, "strncat is unportable - "
706 "use gnulib module strncat for portability");
707 # endif
708 #endif
710 /* Return a newly allocated copy of at most N bytes of STRING. */
711 #if @GNULIB_STRNDUP@
712 # if @REPLACE_STRNDUP@
713 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
714 # undef strndup
715 # define strndup rpl_strndup
716 # endif
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));
722 # else
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);
730 # else
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);
735 # endif
736 # endif
737 _GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n));
738 # endif
739 _GL_CXXALIASWARN (strndup);
740 #else
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);
749 # else
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);
754 # endif
755 # endif
756 # if defined GNULIB_POSIXCHECK
757 # undef strndup
758 # if HAVE_RAW_DECL_STRNDUP
759 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
760 "use gnulib module strndup for portability");
761 # endif
762 # endif
763 #endif
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,
767 return MAXLEN. */
768 #if @GNULIB_STRNLEN@
769 # if @REPLACE_STRNLEN@
770 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
771 # undef strnlen
772 # define strnlen rpl_strnlen
773 # endif
774 _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen)
775 _GL_ATTRIBUTE_PURE
776 _GL_ARG_NONNULL ((1)));
777 _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen));
778 # else
779 # if ! @HAVE_DECL_STRNLEN@
780 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen)
781 _GL_ATTRIBUTE_PURE
782 _GL_ARG_NONNULL ((1)));
783 # endif
784 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__s, size_t __maxlen));
785 # endif
786 _GL_CXXALIASWARN (strnlen);
787 #elif defined GNULIB_POSIXCHECK
788 # undef strnlen
789 # if HAVE_RAW_DECL_STRNLEN
790 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
791 "use gnulib module strnlen for portability");
792 # endif
793 #endif
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
799 digit. */
800 # undef strcspn
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");
805 #endif
807 /* Find the first occurrence in S of any character in ACCEPT. */
808 #if @GNULIB_STRPBRK@
809 # if ! @HAVE_STRPBRK@
810 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
811 _GL_ATTRIBUTE_PURE
812 _GL_ARG_NONNULL ((1, 2)));
813 # endif
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);
831 # endif
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
836 digit. */
837 # undef strpbrk
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");
843 # endif
844 #elif defined GNULIB_POSIXCHECK
845 # undef strpbrk
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");
851 # endif
852 #endif
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. */
857 # undef strspn
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");
862 #endif
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. */
867 # undef strrchr
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");
874 #endif
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
883 empty fields.
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(). */
892 #if @GNULIB_STRSEP@
893 # if ! @HAVE_STRSEP@
894 _GL_FUNCDECL_SYS (strsep, char *,
895 (char **restrict __stringp, char const *restrict __delim)
896 _GL_ARG_NONNULL ((1, 2)));
897 # endif
898 _GL_CXXALIAS_SYS (strsep, char *,
899 (char **restrict __stringp, char const *restrict __delim));
900 _GL_CXXALIASWARN (strsep);
901 # if defined GNULIB_POSIXCHECK
902 # undef strsep
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");
906 # endif
907 #elif defined GNULIB_POSIXCHECK
908 # undef strsep
909 # if HAVE_RAW_DECL_STRSEP
910 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
911 "use gnulib module strsep for portability");
912 # endif
913 #endif
915 #if @GNULIB_STRSTR@
916 # if @REPLACE_STRSTR@
917 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
918 # define strstr rpl_strstr
919 # endif
920 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
921 _GL_ATTRIBUTE_PURE
922 _GL_ARG_NONNULL ((1, 2)));
923 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
924 # else
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));
931 # endif
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);
943 # endif
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. */
949 # undef strstr
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");
956 #endif
958 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
959 comparison. */
960 #if @GNULIB_STRCASESTR@
961 # if @REPLACE_STRCASESTR@
962 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
963 # define strcasestr rpl_strcasestr
964 # endif
965 _GL_FUNCDECL_RPL (strcasestr, char *,
966 (const char *haystack, const char *needle)
967 _GL_ATTRIBUTE_PURE
968 _GL_ARG_NONNULL ((1, 2)));
969 _GL_CXXALIAS_RPL (strcasestr, char *,
970 (const char *haystack, const char *needle));
971 # else
972 # if ! @HAVE_STRCASESTR@
973 _GL_FUNCDECL_SYS (strcasestr, char *,
974 (const char *haystack, const char *needle)
975 _GL_ATTRIBUTE_PURE
976 _GL_ARG_NONNULL ((1, 2)));
977 # endif
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));
984 # endif
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);
996 # endif
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
1000 locales. */
1001 # undef strcasestr
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");
1008 # endif
1009 #endif
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";
1015 char *sp;
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)
1036 # undef strtok_r
1037 # define strtok_r rpl_strtok_r
1038 # endif
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));
1046 # else
1047 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
1048 # undef strtok_r
1049 # endif
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)));
1055 # endif
1056 _GL_CXXALIAS_SYS (strtok_r, char *,
1057 (char *restrict s, char const *restrict delim,
1058 char **restrict save_ptr));
1059 # endif
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");
1065 # endif
1066 #elif defined GNULIB_POSIXCHECK
1067 # undef strtok_r
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");
1071 # endif
1072 #endif
1075 /* The following functions are not specified by POSIX. They are gnulib
1076 extensions. */
1078 #if @GNULIB_MBSLEN@
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. */
1082 # undef mbslen
1083 # endif
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
1087 # endif
1088 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string)
1089 _GL_ATTRIBUTE_PURE
1090 _GL_ARG_NONNULL ((1)));
1091 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
1092 # else
1093 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string)
1094 _GL_ATTRIBUTE_PURE
1095 _GL_ARG_NONNULL ((1)));
1096 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
1097 # endif
1098 # if __GLIBC__ >= 2
1099 _GL_CXXALIASWARN (mbslen);
1100 # endif
1101 #endif
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)
1107 _GL_ATTRIBUTE_PURE
1108 _GL_ARG_NONNULL ((1));
1109 #endif
1111 #if @GNULIB_MBSCHR@
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. */
1116 # if defined __hpux
1117 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1118 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
1119 # endif
1120 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
1121 _GL_ATTRIBUTE_PURE
1122 _GL_ARG_NONNULL ((1)));
1123 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
1124 # else
1125 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
1126 _GL_ATTRIBUTE_PURE
1127 _GL_ARG_NONNULL ((1)));
1128 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
1129 # endif
1130 _GL_CXXALIASWARN (mbschr);
1131 #endif
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 */
1141 # endif
1142 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
1143 _GL_ATTRIBUTE_PURE
1144 _GL_ARG_NONNULL ((1)));
1145 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
1146 # else
1147 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
1148 _GL_ATTRIBUTE_PURE
1149 _GL_ARG_NONNULL ((1)));
1150 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
1151 # endif
1152 _GL_CXXALIASWARN (mbsrchr);
1153 #endif
1155 #if @GNULIB_MBSSTR@
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)
1161 _GL_ATTRIBUTE_PURE
1162 _GL_ARG_NONNULL ((1, 2));
1163 #endif
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
1168 or greater than S2.
1169 Note: This function may, in multibyte locales, return 0 for strings of
1170 different lengths!
1171 Unlike strcasecmp(), this function works correctly in multibyte locales. */
1172 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
1173 _GL_ATTRIBUTE_PURE
1174 _GL_ARG_NONNULL ((1, 2));
1175 #endif
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)
1188 _GL_ATTRIBUTE_PURE
1189 _GL_ARG_NONNULL ((1, 2));
1190 #endif
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
1200 locales. */
1201 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
1202 _GL_ATTRIBUTE_PURE
1203 _GL_ARG_NONNULL ((1, 2));
1204 #endif
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)
1213 _GL_ATTRIBUTE_PURE
1214 _GL_ARG_NONNULL ((1, 2));
1215 #endif
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
1221 if none exists.
1222 Unlike strcspn(), this function works correctly in multibyte locales. */
1223 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
1224 _GL_ATTRIBUTE_PURE
1225 _GL_ARG_NONNULL ((1, 2));
1226 #endif
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
1231 exists.
1232 Unlike strpbrk(), this function works correctly in multibyte locales. */
1233 # if defined __hpux
1234 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1235 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1236 # endif
1237 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
1238 _GL_ATTRIBUTE_PURE
1239 _GL_ARG_NONNULL ((1, 2)));
1240 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
1241 # else
1242 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
1243 _GL_ATTRIBUTE_PURE
1244 _GL_ARG_NONNULL ((1, 2)));
1245 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
1246 # endif
1247 _GL_CXXALIASWARN (mbspbrk);
1248 #endif
1250 #if @GNULIB_MBSSPN@
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
1254 if none exists.
1255 Unlike strspn(), this function works correctly in multibyte locales. */
1256 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
1257 _GL_ATTRIBUTE_PURE
1258 _GL_ARG_NONNULL ((1, 2));
1259 #endif
1261 #if @GNULIB_MBSSEP@
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));
1278 #endif
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";
1286 char *sp;
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,
1298 char **save_ptr)
1299 _GL_ARG_NONNULL ((2, 3));
1300 #endif
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)
1306 # undef strerror
1307 # define strerror rpl_strerror
1308 # endif
1309 _GL_FUNCDECL_RPL (strerror, char *, (int));
1310 _GL_CXXALIAS_RPL (strerror, char *, (int));
1311 # else
1312 _GL_CXXALIAS_SYS (strerror, char *, (int));
1313 # endif
1314 # if __GLIBC__ >= 2
1315 _GL_CXXALIASWARN (strerror);
1316 # endif
1317 #elif defined GNULIB_POSIXCHECK
1318 # undef strerror
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");
1322 #endif
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)
1329 # undef strerror_r
1330 # define strerror_r rpl_strerror_r
1331 # endif
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));
1335 # else
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)));
1339 # endif
1340 _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
1341 # endif
1342 # if __GLIBC__ >= 2 && @HAVE_DECL_STRERROR_R@
1343 _GL_CXXALIASWARN (strerror_r);
1344 # endif
1345 #elif defined GNULIB_POSIXCHECK
1346 # undef strerror_r
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");
1350 # endif
1351 #endif
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
1359 # endif
1360 _GL_FUNCDECL_RPL (strerrorname_np, const char *, (int errnum));
1361 _GL_CXXALIAS_RPL (strerrorname_np, const char *, (int errnum));
1362 # else
1363 # if !@HAVE_STRERRORNAME_NP@
1364 _GL_FUNCDECL_SYS (strerrorname_np, const char *, (int errnum));
1365 # endif
1366 _GL_CXXALIAS_SYS (strerrorname_np, const char *, (int errnum));
1367 # endif
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");
1374 # endif
1375 #endif
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));
1381 # endif
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");
1389 # endif
1390 #endif
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));
1396 # endif
1397 _GL_CXXALIAS_SYS (sigdescr_np, const char *, (int sig));
1398 _GL_CXXALIASWARN (sigdescr_np);
1399 #elif defined GNULIB_POSIXCHECK
1400 # undef sigdescr_np
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");
1404 # endif
1405 #endif
1407 #if @GNULIB_STRSIGNAL@
1408 # if @REPLACE_STRSIGNAL@
1409 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1410 # define strsignal rpl_strsignal
1411 # endif
1412 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
1413 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
1414 # else
1415 # if ! @HAVE_DECL_STRSIGNAL@
1416 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
1417 # endif
1418 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
1419 'const char *'. */
1420 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
1421 # endif
1422 _GL_CXXALIASWARN (strsignal);
1423 #elif defined GNULIB_POSIXCHECK
1424 # undef strsignal
1425 # if HAVE_RAW_DECL_STRSIGNAL
1426 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
1427 "use gnulib module strsignal for portability");
1428 # endif
1429 #endif
1431 #if @GNULIB_STRVERSCMP@
1432 # if @REPLACE_STRVERSCMP@
1433 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1434 # define strverscmp rpl_strverscmp
1435 # endif
1436 _GL_FUNCDECL_RPL (strverscmp, int, (const char *, const char *)
1437 _GL_ATTRIBUTE_PURE
1438 _GL_ARG_NONNULL ((1, 2)));
1439 _GL_CXXALIAS_RPL (strverscmp, int, (const char *, const char *));
1440 # else
1441 # if !@HAVE_STRVERSCMP@
1442 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
1443 _GL_ATTRIBUTE_PURE
1444 _GL_ARG_NONNULL ((1, 2)));
1445 # endif
1446 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
1447 # endif
1448 _GL_CXXALIASWARN (strverscmp);
1449 #elif defined GNULIB_POSIXCHECK
1450 # undef strverscmp
1451 # if HAVE_RAW_DECL_STRVERSCMP
1452 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1453 "use gnulib module strverscmp for portability");
1454 # endif
1455 #endif
1458 #endif /* _@GUARD_PREFIX@_STRING_H */
1459 #endif /* _@GUARD_PREFIX@_STRING_H */
1460 #endif