Debian Codegraph @

lib/string.in.h

raw
1 /* A GNU-like <string.h>.
2
3 Copyright (C) 1995-1996, 2001-2026 Free Software Foundation, Inc.
4
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.
9
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.
14
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/>. */
17
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
22
23 #if defined _@GUARD_PREFIX@_ALREADY_INCLUDING_STRING_H
24 /* Special invocation convention:
25 - On OS X/NetBSD we have a sequence of nested includes
26 <string.h> -> <strings.h> -> "string.h"
27 In this situation system _chk variants due to -D_FORTIFY_SOURCE
28 might be used after any replacements defined here. */
29
30 #@INCLUDE_NEXT@ @NEXT_STRING_H@
31
32 #else
33 /* Normal invocation convention. */
34
35 #ifndef _@GUARD_PREFIX@_STRING_H
36
37 #define _@GUARD_PREFIX@_ALREADY_INCLUDING_STRING_H
38
39 /* The include_next requires a split double-inclusion guard. */
40 #@INCLUDE_NEXT@ @NEXT_STRING_H@
41
42 #undef _@GUARD_PREFIX@_ALREADY_INCLUDING_STRING_H
43
44 #ifndef _@GUARD_PREFIX@_STRING_H
45 #define _@GUARD_PREFIX@_STRING_H
46
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
53
54 /* NetBSD 5.0 mis-defines NULL. */
55 #include <stddef.h>
56
57 #if @GNULIB_STRERROR_L@
58 /* Get locale_t. */
59 # include <locale.h>
60 #endif
61
62 /* MirBSD defines mbslen as a macro. */
63 #if @GNULIB_MBSLEN@ && defined __MirBSD__
64 # include <wchar.h>
65 #endif
66
67 /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
68 /* But in any case avoid namespace pollution on glibc systems. */
69 #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
70 && ! defined __GLIBC__
71 # include <unistd.h>
72 #endif
73
74 /* AIX 7.2 and Android 13 declare ffsl and ffsll in <strings.h>, not in
75 <string.h>. */
76 /* But in any case avoid namespace pollution on glibc systems. */
77 #if ((@GNULIB_FFSL@ || @GNULIB_FFSLL@ || defined GNULIB_POSIXCHECK) \
78 && (defined _AIX || defined __ANDROID__)) \
79 && ! defined __GLIBC__
80 # include <strings.h>
81 #endif
82
83 _GL_INLINE_HEADER_BEGIN
84
85 #ifndef _GL_STRING_INLINE
86 # define _GL_STRING_INLINE _GL_INLINE
87 #endif
88
89 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
90 that can be freed by passing them as the Ith argument to the
91 function F. */
92 #ifndef _GL_ATTRIBUTE_DEALLOC
93 # if __GNUC__ >= 11 && !defined __clang__
94 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
95 # else
96 # define _GL_ATTRIBUTE_DEALLOC(f, i)
97 # endif
98 #endif
99
100 /* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
101 can be freed via 'free'; it can be used only after declaring 'free'. */
102 /* Applies to: functions. Cannot be used on inline functions. */
103 #ifndef _GL_ATTRIBUTE_DEALLOC_FREE
104 # if defined __cplusplus && defined __GNUC__ && !defined __clang__
105 /* Work around GCC bug <https://gcc.gnu.org/PR108231> */
106 # define _GL_ATTRIBUTE_DEALLOC_FREE \
107 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
108 # else
109 # define _GL_ATTRIBUTE_DEALLOC_FREE \
110 _GL_ATTRIBUTE_DEALLOC (free, 1)
111 # endif
112 #endif
113
114 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
115 allocated memory. */
116 /* Applies to: functions. */
117 #ifndef _GL_ATTRIBUTE_MALLOC
118 # if __GNUC__ >= 3 || defined __clang__
119 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
120 # else
121 # define _GL_ATTRIBUTE_MALLOC
122 # endif
123 #endif
124
125 /* _GL_ATTRIBUTE_NONNULL_IF_NONZERO (NP, NI) declares that the argument NP
126 (a pointer) must not be NULL if the argument NI (an integer) is != 0. */
127 /* Applies to: functions. */
128 #ifndef _GL_ATTRIBUTE_NONNULL_IF_NONZERO
129 # if __GNUC__ >= 15 && !defined __clang__
130 # define _GL_ATTRIBUTE_NONNULL_IF_NONZERO(np, ni) \
131 __attribute__ ((__nonnull_if_nonzero__ (np, ni)))
132 # else
133 # define _GL_ATTRIBUTE_NONNULL_IF_NONZERO(np, ni)
134 # endif
135 #endif
136
137 /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
138 */
139 #ifndef _GL_ATTRIBUTE_NOTHROW
140 # if defined __cplusplus
141 # if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major__ >= 4
142 # if __cplusplus >= 201103L
143 # define _GL_ATTRIBUTE_NOTHROW noexcept (true)
144 # else
145 # define _GL_ATTRIBUTE_NOTHROW throw ()
146 # endif
147 # else
148 # define _GL_ATTRIBUTE_NOTHROW
149 # endif
150 # else
151 # if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__
152 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
153 # else
154 # define _GL_ATTRIBUTE_NOTHROW
155 # endif
156 # endif
157 #endif
158
159 /* The __attribute__ feature is available in gcc versions 2.5 and later.
160 The attribute __pure__ was added in gcc 2.96. */
161 #ifndef _GL_ATTRIBUTE_PURE
162 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
163 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
164 # else
165 # define _GL_ATTRIBUTE_PURE /* empty */
166 # endif
167 #endif
168
169 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
170
171 /* The definition of _GL_ARG_NONNULL is copied here. */
172
173 /* The definition of _GL_WARN_ON_USE is copied here. */
174
175
176 /* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though <stdlib.h> may not have
177 been included yet. */
178 #if @GNULIB_FREE_POSIX@
179 # if (@REPLACE_FREE@ && !defined free \
180 && !(defined __cplusplus && defined GNULIB_NAMESPACE))
181 /* We can't do '#define free rpl_free' here. */
182 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
183 _GL_EXTERN_C void rpl_free (void *) _GL_ATTRIBUTE_NOTHROW;
184 # else
185 _GL_EXTERN_C void rpl_free (void *);
186 # endif
187 # undef _GL_ATTRIBUTE_DEALLOC_FREE
188 # define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
189 # else
190 # if defined _MSC_VER && !defined free
191 _GL_EXTERN_C
192 # if defined _DLL
193 __declspec (dllimport)
194 # endif
195 void __cdecl free (void *);
196 # else
197 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
198 _GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
199 # else
200 _GL_EXTERN_C void free (void *);
201 # endif
202 # endif
203 # endif
204 #else
205 # if defined _MSC_VER && !defined free
206 _GL_EXTERN_C
207 # if defined _DLL
208 __declspec (dllimport)
209 # endif
210 void __cdecl free (void *);
211 # else
212 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
213 _GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW;
214 # else
215 _GL_EXTERN_C void free (void *);
216 # endif
217 # endif
218 #endif
219
220
221 /* Declarations for ISO C N3322. */
222 #if defined __GNUC__ && __GNUC__ >= 15 && !defined __clang__
223 # ifndef memcpy
224 _GL_EXTERN_C void *memcpy (void *__dest, const void *__src, size_t __n)
225 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
226 _GL_ATTRIBUTE_NOTHROW
227 # endif
228 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
229 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
230 # endif
231 # ifndef memccpy
232 _GL_EXTERN_C void *memccpy (void *__dest, const void *__src, int __c, size_t __n)
233 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
234 _GL_ATTRIBUTE_NOTHROW
235 # endif
236 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 4)
237 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 4);
238 # endif
239 # ifndef memmove
240 _GL_EXTERN_C void *memmove (void *__dest, const void *__src, size_t __n)
241 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
242 _GL_ATTRIBUTE_NOTHROW
243 # endif
244 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
245 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
246 # endif
247 # ifndef strncpy
248 _GL_EXTERN_C char *strncpy (char *__dest, const char *__src, size_t __n)
249 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
250 _GL_ATTRIBUTE_NOTHROW
251 # endif
252 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
253 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
254 # endif
255 # ifndef strndup
256 _GL_EXTERN_C char *strndup (const char *__s, size_t __n)
257 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
258 _GL_ATTRIBUTE_NOTHROW
259 # endif
260 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2);
261 # endif
262 # ifndef strncat
263 _GL_EXTERN_C char *strncat (char *__dest, const char *__src, size_t __n)
264 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
265 _GL_ATTRIBUTE_NOTHROW
266 # endif
267 _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
268 # endif
269 # ifndef memcmp
270 _GL_EXTERN_C int memcmp (const void *__s1, const void *__s2, size_t __n)
271 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
272 _GL_ATTRIBUTE_NOTHROW
273 # endif
274 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
275 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
276 # endif
277 # ifndef strncmp
278 _GL_EXTERN_C int strncmp (const char *__s1, const char *__s2, size_t __n)
279 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
280 _GL_ATTRIBUTE_NOTHROW
281 # endif
282 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
283 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
284 # endif
285 # if !defined memchr && !defined __cplusplus
286 _GL_EXTERN_C void *memchr (const void *__s, int __c, size_t __n)
287 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3);
288 _GL_EXTERN_C void *memrchr (const void *__s, int __c, size_t __n)
289 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3);
290 # endif
291 # ifndef memset
292 _GL_EXTERN_C void *memset (void *__s, int __c, size_t __n)
293 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
294 _GL_ATTRIBUTE_NOTHROW
295 # endif
296 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3);
297 # endif
298 # ifndef memset_explicit
299 _GL_EXTERN_C void *memset_explicit (void *__s, int __c, size_t __n)
300 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3);
301 # endif
302 #endif
303
304
305 /* Clear a block of memory. The compiler will not delete a call to
306 this function, even if the block is dead after the call. */
307 #if @GNULIB_EXPLICIT_BZERO@
308 # if ! @HAVE_EXPLICIT_BZERO@
309 _GL_FUNCDECL_SYS (explicit_bzero, void,
310 (void *__dest, size_t __n), _GL_ARG_NONNULL ((1)));
311 # endif
312 _GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n));
313 _GL_CXXALIASWARN (explicit_bzero);
314 #elif defined GNULIB_POSIXCHECK
315 # if HAVE_RAW_DECL_EXPLICIT_BZERO
316 _GL_WARN_ON_USE (explicit_bzero, "explicit_bzero is unportable - "
317 "use gnulib module explicit_bzero for portability");
318 # endif
319 #endif
320
321
322 /* Find the index of the least-significant set bit. */
323 #if @GNULIB_FFSL@
324 # if !@HAVE_FFSL@
325 _GL_FUNCDECL_SYS (ffsl, int, (long int i), );
326 # endif
327 _GL_CXXALIAS_SYS (ffsl, int, (long int i));
328 _GL_CXXALIASWARN (ffsl);
329 #elif defined GNULIB_POSIXCHECK
330 # if HAVE_RAW_DECL_FFSL
331 _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
332 # endif
333 #endif
334
335
336 /* Find the index of the least-significant set bit. */
337 #if @GNULIB_FFSLL@
338 # if @REPLACE_FFSLL@
339 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
340 # define ffsll rpl_ffsll
341 # endif
342 _GL_FUNCDECL_RPL (ffsll, int, (long long int i), );
343 _GL_CXXALIAS_RPL (ffsll, int, (long long int i));
344 # else
345 # if !@HAVE_FFSLL@
346 _GL_FUNCDECL_SYS (ffsll, int, (long long int i), );
347 # endif
348 _GL_CXXALIAS_SYS (ffsll, int, (long long int i));
349 # endif
350 _GL_CXXALIASWARN (ffsll);
351 #elif defined GNULIB_POSIXCHECK
352 # if HAVE_RAW_DECL_FFSLL
353 _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
354 # endif
355 #endif
356
357
358 #if @GNULIB_MDA_MEMCCPY@
359 /* On native Windows, map 'memccpy' to '_memccpy', so that -loldnames is not
360 required. In C++ with GNULIB_NAMESPACE, avoid differences between
361 platforms by defining GNULIB_NAMESPACE::memccpy always. */
362 # if defined _WIN32 && !defined __CYGWIN__
363 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
364 # undef memccpy
365 # define memccpy _memccpy
366 # endif
367 _GL_CXXALIAS_MDA (memccpy, void *,
368 (void *dest, const void *src, int c, size_t n));
369 # else
370 _GL_CXXALIAS_SYS (memccpy, void *,
371 (void *dest, const void *src, int c, size_t n));
372 # endif
373 _GL_CXXALIASWARN (memccpy);
374 #endif
375
376
377 /* Return the first instance of C within N bytes of S, or NULL. */
378 #if @GNULIB_MEMCHR@
379 # if @REPLACE_MEMCHR@
380 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
381 # undef memchr
382 # define memchr rpl_memchr
383 # endif
384 _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n),
385 _GL_ATTRIBUTE_PURE
386 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3));
387 _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
388 # else
389 /* On some systems, this function is defined as an overloaded function:
390 extern "C" { const void * std::memchr (const void *, int, size_t); }
391 extern "C++" { void * std::memchr (void *, int, size_t); } */
392 _GL_CXXALIAS_SYS_CAST2 (memchr,
393 void *, (void const *__s, int __c, size_t __n),
394 void const *, (void const *__s, int __c, size_t __n));
395 # endif
396 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
397 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
398 || defined __clang__)
399 _GL_CXXALIASWARN1 (memchr, void *,
400 (void *__s, int __c, size_t __n)
401 _GL_ATTRIBUTE_NOTHROW);
402 _GL_CXXALIASWARN1 (memchr, void const *,
403 (void const *__s, int __c, size_t __n)
404 _GL_ATTRIBUTE_NOTHROW);
405 # elif __GLIBC__ >= 2
406 _GL_CXXALIASWARN (memchr);
407 # endif
408 #elif defined GNULIB_POSIXCHECK
409 /* Assume memchr is always declared. */
410 _GL_WARN_ON_USE_CXX (memchr,
411 const void *, void *, (void const *, int, size_t),
412 "memchr has platform-specific bugs - "
413 "use gnulib module memchr for portability" );
414 #endif
415
416 /* Are S1 and S2, of size N, bytewise equal? */
417 #if @GNULIB_STRINGEQ@ && !@HAVE_DECL_MEMEQ@
418 # ifdef __cplusplus
419 extern "C" {
420 # endif
421 _GL_STRING_INLINE bool
422 memeq (void const *__s1, void const *__s2, size_t __n)
423 {
424 return !memcmp (__s1, __s2, __n);
425 }
426 # ifdef __cplusplus
427 }
428 # endif
429 #endif
430
431 /* Return the first occurrence of NEEDLE in HAYSTACK. */
432 #if @GNULIB_MEMMEM@
433 # if @REPLACE_MEMMEM@
434 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
435 # define memmem rpl_memmem
436 # endif
437 _GL_FUNCDECL_RPL (memmem, void *,
438 (void const *__haystack, size_t __haystack_len,
439 void const *__needle, size_t __needle_len),
440 _GL_ATTRIBUTE_PURE
441 _GL_ARG_NONNULL ((1, 3)));
442 _GL_CXXALIAS_RPL (memmem, void *,
443 (void const *__haystack, size_t __haystack_len,
444 void const *__needle, size_t __needle_len));
445 # else
446 # if ! @HAVE_DECL_MEMMEM@
447 _GL_FUNCDECL_SYS (memmem, void *,
448 (void const *__haystack, size_t __haystack_len,
449 void const *__needle, size_t __needle_len),
450 _GL_ATTRIBUTE_PURE
451 _GL_ARG_NONNULL ((1, 3)));
452 # endif
453 _GL_CXXALIAS_SYS (memmem, void *,
454 (void const *__haystack, size_t __haystack_len,
455 void const *__needle, size_t __needle_len));
456 # endif
457 _GL_CXXALIASWARN (memmem);
458 #elif defined GNULIB_POSIXCHECK
459 # if HAVE_RAW_DECL_MEMMEM
460 _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
461 "use gnulib module memmem-simple for portability, "
462 "and module memmem for speed" );
463 # endif
464 #endif
465
466 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
467 last written byte. */
468 #if @GNULIB_MEMPCPY@
469 # if @REPLACE_MEMPCPY@
470 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
471 # undef mempcpy
472 # define mempcpy rpl_mempcpy
473 # endif
474 _GL_FUNCDECL_RPL (mempcpy, void *,
475 (void *restrict __dest, void const *restrict __src,
476 size_t __n),
477 _GL_ARG_NONNULL ((1, 2)));
478 _GL_CXXALIAS_RPL (mempcpy, void *,
479 (void *restrict __dest, void const *restrict __src,
480 size_t __n));
481 # else
482 # if !@HAVE_MEMPCPY@
483 _GL_FUNCDECL_SYS (mempcpy, void *,
484 (void *restrict __dest, void const *restrict __src,
485 size_t __n),
486 _GL_ARG_NONNULL ((1, 2)));
487 # endif
488 _GL_CXXALIAS_SYS (mempcpy, void *,
489 (void *restrict __dest, void const *restrict __src,
490 size_t __n));
491 # endif
492 # if __GLIBC__ >= 2
493 _GL_CXXALIASWARN (mempcpy);
494 # endif
495 #elif defined GNULIB_POSIXCHECK
496 # if HAVE_RAW_DECL_MEMPCPY
497 _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
498 "use gnulib module mempcpy for portability");
499 # endif
500 #endif
501
502 /* Search backwards through a block for a byte (specified as an int). */
503 #if @GNULIB_MEMRCHR@
504 # if ! @HAVE_DECL_MEMRCHR@
505 _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t),
506 _GL_ATTRIBUTE_PURE
507 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3));
508 # endif
509 /* On some systems, this function is defined as an overloaded function:
510 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
511 extern "C++" { void * std::memrchr (void *, int, size_t); } */
512 _GL_CXXALIAS_SYS_CAST2 (memrchr,
513 void *, (void const *, int, size_t),
514 void const *, (void const *, int, size_t));
515 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
516 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
517 || defined __clang__)
518 _GL_CXXALIASWARN1 (memrchr, void *,
519 (void *, int, size_t)
520 _GL_ATTRIBUTE_NOTHROW);
521 _GL_CXXALIASWARN1 (memrchr, void const *,
522 (void const *, int, size_t)
523 _GL_ATTRIBUTE_NOTHROW);
524 # elif __GLIBC__ >= 2
525 _GL_CXXALIASWARN (memrchr);
526 # endif
527 #elif defined GNULIB_POSIXCHECK
528 # if HAVE_RAW_DECL_MEMRCHR
529 _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
530 "use gnulib module memrchr for portability");
531 # endif
532 #endif
533
534 /* Overwrite a block of memory. The compiler will not optimize
535 effects away, even if the block is dead after the call. */
536 #if @GNULIB_MEMSET_EXPLICIT@
537 # if @REPLACE_MEMSET_EXPLICIT@
538 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
539 # undef memset_explicit
540 # define memset_explicit rpl_memset_explicit
541 # endif
542 _GL_FUNCDECL_RPL (memset_explicit, void *,
543 (void *__dest, int __c, size_t __n),
544 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3));
545 _GL_CXXALIAS_RPL (memset_explicit, void *, (void *__dest, int __c, size_t __n));
546 # else
547 # if !@HAVE_MEMSET_EXPLICIT@
548 _GL_FUNCDECL_SYS (memset_explicit, void *,
549 (void *__dest, int __c, size_t __n),
550 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3));
551 # endif
552 _GL_CXXALIAS_SYS (memset_explicit, void *, (void *__dest, int __c, size_t __n));
553 # endif
554 # if __GLIBC__ >= 2
555 _GL_CXXALIASWARN (memset_explicit);
556 # endif
557 #elif defined GNULIB_POSIXCHECK
558 # if HAVE_RAW_DECL_MEMSET_EXPLICIT
559 _GL_WARN_ON_USE (memset_explicit, "memset_explicit is unportable - "
560 "use gnulib module memset_explicit for portability");
561 # endif
562 #endif
563
564 /* Find the first occurrence of C in S. More efficient than
565 memchr(S,C,N), at the expense of undefined behavior if C does not
566 occur within N bytes. */
567 #if @GNULIB_RAWMEMCHR@
568 # if ! @HAVE_RAWMEMCHR@
569 _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in),
570 _GL_ATTRIBUTE_PURE
571 _GL_ARG_NONNULL ((1)));
572 # endif
573 /* On some systems, this function is defined as an overloaded function:
574 extern "C++" { const void * std::rawmemchr (const void *, int); }
575 extern "C++" { void * std::rawmemchr (void *, int); } */
576 _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
577 void *, (void const *__s, int __c_in),
578 void const *, (void const *__s, int __c_in));
579 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
580 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
581 || defined __clang__)
582 _GL_CXXALIASWARN1 (rawmemchr, void *,
583 (void *__s, int __c_in)
584 _GL_ATTRIBUTE_NOTHROW);
585 _GL_CXXALIASWARN1 (rawmemchr, void const *,
586 (void const *__s, int __c_in)
587 _GL_ATTRIBUTE_NOTHROW);
588 # else
589 _GL_CXXALIASWARN (rawmemchr);
590 # endif
591 #elif defined GNULIB_POSIXCHECK
592 # if HAVE_RAW_DECL_RAWMEMCHR
593 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
594 "use gnulib module rawmemchr for portability");
595 # endif
596 #endif
597
598 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
599 #if @GNULIB_STPCPY@
600 # if @REPLACE_STPCPY@
601 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
602 # undef stpcpy
603 # define stpcpy rpl_stpcpy
604 # endif
605 _GL_FUNCDECL_RPL (stpcpy, char *,
606 (char *restrict __dst, char const *restrict __src),
607 _GL_ARG_NONNULL ((1, 2)));
608 _GL_CXXALIAS_RPL (stpcpy, char *,
609 (char *restrict __dst, char const *restrict __src));
610 # else
611 # if !@HAVE_STPCPY@
612 _GL_FUNCDECL_SYS (stpcpy, char *,
613 (char *restrict __dst, char const *restrict __src),
614 _GL_ARG_NONNULL ((1, 2)));
615 # endif
616 _GL_CXXALIAS_SYS (stpcpy, char *,
617 (char *restrict __dst, char const *restrict __src));
618 # endif
619 # if __GLIBC__ >= 2
620 _GL_CXXALIASWARN (stpcpy);
621 # endif
622 #elif defined GNULIB_POSIXCHECK
623 # if HAVE_RAW_DECL_STPCPY
624 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
625 "use gnulib module stpcpy for portability");
626 # endif
627 #endif
628
629 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
630 last non-NUL byte written into DST. */
631 #if @GNULIB_STPNCPY@
632 # if @REPLACE_STPNCPY@
633 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
634 # undef stpncpy
635 # define stpncpy rpl_stpncpy
636 # endif
637 _GL_FUNCDECL_RPL (stpncpy, char *,
638 (char *restrict __dst, char const *restrict __src,
639 size_t __n),
640 _GL_ARG_NONNULL ((1, 2)));
641 _GL_CXXALIAS_RPL (stpncpy, char *,
642 (char *restrict __dst, char const *restrict __src,
643 size_t __n));
644 # else
645 # if ! @HAVE_STPNCPY@
646 _GL_FUNCDECL_SYS (stpncpy, char *,
647 (char *restrict __dst, char const *restrict __src,
648 size_t __n),
649 _GL_ARG_NONNULL ((1, 2)));
650 # endif
651 _GL_CXXALIAS_SYS (stpncpy, char *,
652 (char *restrict __dst, char const *restrict __src,
653 size_t __n));
654 # endif
655 # if __GLIBC__ >= 2
656 _GL_CXXALIASWARN (stpncpy);
657 # endif
658 #elif defined GNULIB_POSIXCHECK
659 # if HAVE_RAW_DECL_STPNCPY
660 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
661 "use gnulib module stpncpy for portability");
662 # endif
663 #endif
664
665 #if defined GNULIB_POSIXCHECK
666 /* strchr() does not work with multibyte strings if the locale encoding is
667 GB18030 and the character to be searched is a digit. */
668 /* Assume strchr is always declared. */
669 _GL_WARN_ON_USE_CXX (strchr,
670 const char *, char *, (const char *, int),
671 "strchr cannot work correctly on character strings "
672 "in some multibyte locales - "
673 "use mbschr if you care about internationalization");
674 #endif
675
676 /* Find the first occurrence of C in S or the final NUL byte. */
677 #if @GNULIB_STRCHRNUL@
678 # if @REPLACE_STRCHRNUL@
679 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
680 # define strchrnul rpl_strchrnul
681 # endif
682 _GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in),
683 _GL_ATTRIBUTE_PURE
684 _GL_ARG_NONNULL ((1)));
685 _GL_CXXALIAS_RPL (strchrnul, char *,
686 (const char *str, int ch));
687 # else
688 # if ! @HAVE_STRCHRNUL@
689 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in),
690 _GL_ATTRIBUTE_PURE
691 _GL_ARG_NONNULL ((1)));
692 # endif
693 /* On some systems, this function is defined as an overloaded function:
694 extern "C++" { const char * std::strchrnul (const char *, int); }
695 extern "C++" { char * std::strchrnul (char *, int); } */
696 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
697 char *, (char const *__s, int __c_in),
698 char const *, (char const *__s, int __c_in));
699 # endif
700 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
701 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
702 || defined __clang__)
703 _GL_CXXALIASWARN1 (strchrnul, char *,
704 (char *__s, int __c_in)
705 _GL_ATTRIBUTE_NOTHROW);
706 _GL_CXXALIASWARN1 (strchrnul, char const *,
707 (char const *__s, int __c_in)
708 _GL_ATTRIBUTE_NOTHROW);
709 # elif __GLIBC__ >= 2
710 _GL_CXXALIASWARN (strchrnul);
711 # endif
712 #elif defined GNULIB_POSIXCHECK
713 # if HAVE_RAW_DECL_STRCHRNUL
714 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
715 "use gnulib module strchrnul for portability");
716 # endif
717 #endif
718
719 /* Duplicate S, returning an identical malloc'd string. */
720 #if @GNULIB_STRDUP@
721 # if @REPLACE_STRDUP@
722 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
723 # undef strdup
724 # define strdup rpl_strdup
725 # endif
726 _GL_FUNCDECL_RPL (strdup, char *,
727 (char const *__s),
728 _GL_ARG_NONNULL ((1))
729 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
730 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
731 # elif defined _WIN32 && !defined __CYGWIN__
732 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
733 # undef strdup
734 # define strdup _strdup
735 # endif
736 _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
737 # else
738 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
739 /* strdup exists as a function and as a macro. Get rid of the macro. */
740 # undef strdup
741 # endif
742 # if (!@HAVE_DECL_STRDUP@ || (__GNUC__ >= 11 && !defined __clang__)) \
743 && !defined strdup
744 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
745 _GL_FUNCDECL_SYS (strdup, char *,
746 (char const *__s),
747 _GL_ARG_NONNULL ((1))
748 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE)
749 _GL_ATTRIBUTE_NOTHROW;
750 # else
751 _GL_FUNCDECL_SYS (strdup, char *,
752 (char const *__s),
753 _GL_ARG_NONNULL ((1))
754 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
755 # endif
756 # endif
757 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
758 # endif
759 _GL_CXXALIASWARN (strdup);
760 #else
761 # if (__GNUC__ >= 11 && !defined __clang__) && !defined strdup
762 /* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */
763 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
764 _GL_FUNCDECL_SYS (strdup, char *,
765 (char const *__s),
766 _GL_ARG_NONNULL ((1))
767 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE)
768 _GL_ATTRIBUTE_NOTHROW;
769 # else
770 _GL_FUNCDECL_SYS (strdup, char *,
771 (char const *__s),
772 _GL_ARG_NONNULL ((1))
773 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
774 # endif
775 # endif
776 # if defined GNULIB_POSIXCHECK
777 # if HAVE_RAW_DECL_STRDUP
778 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
779 "use gnulib module strdup for portability");
780 # endif
781 # elif @GNULIB_MDA_STRDUP@
782 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
783 required. In C++ with GNULIB_NAMESPACE, avoid differences between
784 platforms by defining GNULIB_NAMESPACE::strdup always. */
785 # if defined _WIN32 && !defined __CYGWIN__
786 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
787 # undef strdup
788 # define strdup _strdup
789 # endif
790 _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
791 # else
792 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
793 # undef strdup
794 # endif
795 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
796 # endif
797 _GL_CXXALIASWARN (strdup);
798 # endif
799 #endif
800
801 /* Are strings S1 and S2 equal? */
802 #if @GNULIB_STRINGEQ@ && !@HAVE_DECL_STREQ@
803 # ifdef __cplusplus
804 extern "C" {
805 # endif
806 _GL_STRING_INLINE bool
807 streq (char const *__s1, char const *__s2)
808 {
809 return !strcmp (__s1, __s2);
810 }
811 # ifdef __cplusplus
812 }
813 # endif
814 #endif
815
816 /* Append no more than N characters from SRC onto DEST. */
817 #if @GNULIB_STRNCAT@
818 # if @REPLACE_STRNCAT@
819 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
820 # undef strncat
821 # define strncat rpl_strncat
822 # endif
823 _GL_FUNCDECL_RPL (strncat, char *,
824 (char *restrict dest, const char *restrict src, size_t n),
825 _GL_ARG_NONNULL ((1))
826 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3));
827 _GL_CXXALIAS_RPL (strncat, char *,
828 (char *restrict dest, const char *restrict src, size_t n));
829 # else
830 _GL_CXXALIAS_SYS (strncat, char *,
831 (char *restrict dest, const char *restrict src, size_t n));
832 # endif
833 # if __GLIBC__ >= 2
834 _GL_CXXALIASWARN (strncat);
835 # endif
836 #elif defined GNULIB_POSIXCHECK
837 # if HAVE_RAW_DECL_STRNCAT
838 _GL_WARN_ON_USE (strncat, "strncat is unportable - "
839 "use gnulib module strncat for portability");
840 # endif
841 #endif
842
843 /* Copy no more than N bytes of SRC to DST, returning DST. */
844 #if @GNULIB_STRNCPY@
845 # if @REPLACE_STRNCPY@
846 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
847 # undef strncpy
848 # define strncpy rpl_strncpy
849 # endif
850 _GL_FUNCDECL_RPL (strncpy, char *,
851 (char *restrict __dst, char const *restrict __src,
852 size_t __n),
853 _GL_ARG_NONNULL ((1, 2)));
854 _GL_CXXALIAS_RPL (strncpy, char *,
855 (char *restrict __dst, char const *restrict __src,
856 size_t __n));
857 # else
858 _GL_CXXALIAS_SYS (strncpy, char *,
859 (char *restrict __dst, char const *restrict __src,
860 size_t __n));
861 # endif
862 # if __GLIBC__ >= 2
863 _GL_CXXALIASWARN (strncpy);
864 # endif
865 #elif defined GNULIB_POSIXCHECK
866 # if HAVE_RAW_DECL_STRNCPY
867 _GL_WARN_ON_USE (strncpy, "strncpy is unportable - "
868 "use gnulib module strncpy for portability");
869 # endif
870 #endif
871
872 /* Return a newly allocated copy of at most N bytes of STRING. */
873 #if @GNULIB_STRNDUP@
874 # if @REPLACE_STRNDUP@
875 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
876 # undef strndup
877 # define strndup rpl_strndup
878 # endif
879 _GL_FUNCDECL_RPL (strndup, char *,
880 (char const *__s, size_t __n),
881 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
882 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
883 _GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n));
884 # else
885 # if !@HAVE_DECL_STRNDUP@ \
886 || ((__GNUC__ >= 11 && !defined __clang__) && !defined strndup)
887 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
888 _GL_FUNCDECL_SYS (strndup, char *,
889 (char const *__s, size_t __n),
890 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
891 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE)
892 _GL_ATTRIBUTE_NOTHROW;
893 # else
894 _GL_FUNCDECL_SYS (strndup, char *,
895 (char const *__s, size_t __n),
896 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
897 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
898 # endif
899 # endif
900 _GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n));
901 # endif
902 _GL_CXXALIASWARN (strndup);
903 #else
904 # if (__GNUC__ >= 11 && !defined __clang__) && !defined strndup
905 /* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */
906 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
907 _GL_FUNCDECL_SYS (strndup, char *,
908 (char const *__s, size_t __n),
909 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
910 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE)
911 _GL_ATTRIBUTE_NOTHROW;
912 # else
913 _GL_FUNCDECL_SYS (strndup, char *,
914 (char const *__s, size_t __n),
915 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
916 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
917 # endif
918 # endif
919 # if defined GNULIB_POSIXCHECK
920 # if HAVE_RAW_DECL_STRNDUP
921 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
922 "use gnulib module strndup for portability");
923 # endif
924 # endif
925 #endif
926
927 /* Find the length (number of bytes) of STRING, but scan at most
928 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
929 return MAXLEN. */
930 #if @GNULIB_STRNLEN@
931 # if @REPLACE_STRNLEN@
932 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
933 # undef strnlen
934 # define strnlen rpl_strnlen
935 # endif
936 _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen),
937 _GL_ATTRIBUTE_PURE
938 _GL_ARG_NONNULL ((1)));
939 _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen));
940 # else
941 # if ! @HAVE_DECL_STRNLEN@
942 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen),
943 _GL_ATTRIBUTE_PURE
944 _GL_ARG_NONNULL ((1)));
945 # endif
946 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__s, size_t __maxlen));
947 # endif
948 _GL_CXXALIASWARN (strnlen);
949 #elif defined GNULIB_POSIXCHECK
950 # if HAVE_RAW_DECL_STRNLEN
951 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
952 "use gnulib module strnlen for portability");
953 # endif
954 #endif
955
956 #if defined GNULIB_POSIXCHECK
957 /* strcspn() assumes the second argument is a list of single-byte characters.
958 Even in this simple case, it does not work with multibyte strings if the
959 locale encoding is GB18030 and one of the characters to be searched is a
960 digit. */
961 /* Assume strcspn is always declared. */
962 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
963 "in multibyte locales - "
964 "use mbscspn if you care about internationalization");
965 #endif
966
967 /* Find the first occurrence in S of any character in ACCEPT. */
968 #if @GNULIB_STRPBRK@
969 # if ! @HAVE_STRPBRK@
970 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept),
971 _GL_ATTRIBUTE_PURE
972 _GL_ARG_NONNULL ((1, 2)));
973 # endif
974 /* On some systems, this function is defined as an overloaded function:
975 extern "C" { const char * strpbrk (const char *, const char *); }
976 extern "C++" { char * strpbrk (char *, const char *); } */
977 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
978 char *, (char const *__s, char const *__accept),
979 const char *, (char const *__s, char const *__accept));
980 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
981 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
982 || defined __clang__)
983 _GL_CXXALIASWARN1 (strpbrk, char *,
984 (char *__s, char const *__accept)
985 _GL_ATTRIBUTE_NOTHROW);
986 _GL_CXXALIASWARN1 (strpbrk, char const *,
987 (char const *__s, char const *__accept)
988 _GL_ATTRIBUTE_NOTHROW);
989 # elif __GLIBC__ >= 2
990 _GL_CXXALIASWARN (strpbrk);
991 # endif
992 # if defined GNULIB_POSIXCHECK
993 /* strpbrk() assumes the second argument is a list of single-byte characters.
994 Even in this simple case, it does not work with multibyte strings if the
995 locale encoding is GB18030 and one of the characters to be searched is a
996 digit. */
997 _GL_WARN_ON_USE_CXX (strpbrk,
998 const char *, char *, (const char *, const char *),
999 "strpbrk cannot work correctly on character strings "
1000 "in multibyte locales - "
1001 "use mbspbrk if you care about internationalization");
1002 # endif
1003 #elif defined GNULIB_POSIXCHECK
1004 # undef strpbrk
1005 # if HAVE_RAW_DECL_STRPBRK
1006 _GL_WARN_ON_USE_CXX (strpbrk,
1007 const char *, char *, (const char *, const char *),
1008 "strpbrk is unportable - "
1009 "use gnulib module strpbrk for portability");
1010 # endif
1011 #endif
1012
1013 #if defined GNULIB_POSIXCHECK
1014 /* strspn() assumes the second argument is a list of single-byte characters.
1015 Even in this simple case, it cannot work with multibyte strings. */
1016 /* Assume strspn is always declared. */
1017 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
1018 "in multibyte locales - "
1019 "use mbsspn if you care about internationalization");
1020 #endif
1021
1022 #if defined GNULIB_POSIXCHECK
1023 /* strrchr() does not work with multibyte strings if the locale encoding is
1024 GB18030 and the character to be searched is a digit. */
1025 /* Assume strrchr is always declared. */
1026 _GL_WARN_ON_USE_CXX (strrchr,
1027 const char *, char *, (const char *, int),
1028 "strrchr cannot work correctly on character strings "
1029 "in some multibyte locales - "
1030 "use mbsrchr if you care about internationalization");
1031 #endif
1032
1033 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
1034 If one is found, overwrite it with a NUL, and advance *STRINGP
1035 to point to the next char after it. Otherwise, set *STRINGP to NULL.
1036 If *STRINGP was already NULL, nothing happens.
1037 Return the old value of *STRINGP.
1038
1039 This is a variant of strtok() that is multithread-safe and supports
1040 empty fields.
1041
1042 Caveat: It modifies the original string.
1043 Caveat: These functions cannot be used on constant strings.
1044 Caveat: The identity of the delimiting character is lost.
1045 Caveat: It doesn't work with multibyte strings unless all of the delimiter
1046 characters are ASCII characters < 0x30.
1047
1048 See also strtok_r(). */
1049 #if @GNULIB_STRSEP@
1050 # if ! @HAVE_STRSEP@
1051 _GL_FUNCDECL_SYS (strsep, char *,
1052 (char **restrict __stringp, char const *restrict __delim),
1053 _GL_ARG_NONNULL ((1, 2)));
1054 # endif
1055 _GL_CXXALIAS_SYS (strsep, char *,
1056 (char **restrict __stringp, char const *restrict __delim));
1057 _GL_CXXALIASWARN (strsep);
1058 # if defined GNULIB_POSIXCHECK
1059 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
1060 "in multibyte locales - "
1061 "use mbssep if you care about internationalization");
1062 # endif
1063 #elif defined GNULIB_POSIXCHECK
1064 # if HAVE_RAW_DECL_STRSEP
1065 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
1066 "use gnulib module strsep for portability");
1067 # endif
1068 #endif
1069
1070 #if @GNULIB_STRSTR@
1071 # if @REPLACE_STRSTR@
1072 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1073 # define strstr rpl_strstr
1074 # endif
1075 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle),
1076 _GL_ATTRIBUTE_PURE
1077 _GL_ARG_NONNULL ((1, 2)));
1078 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
1079 # else
1080 /* On some systems, this function is defined as an overloaded function:
1081 extern "C++" { const char * strstr (const char *, const char *); }
1082 extern "C++" { char * strstr (char *, const char *); } */
1083 _GL_CXXALIAS_SYS_CAST2 (strstr,
1084 char *, (const char *haystack, const char *needle),
1085 const char *, (const char *haystack, const char *needle));
1086 # endif
1087 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1088 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
1089 || defined __clang__)
1090 _GL_CXXALIASWARN1 (strstr, char *,
1091 (char *haystack, const char *needle)
1092 _GL_ATTRIBUTE_NOTHROW);
1093 _GL_CXXALIASWARN1 (strstr, const char *,
1094 (const char *haystack, const char *needle)
1095 _GL_ATTRIBUTE_NOTHROW);
1096 # elif __GLIBC__ >= 2
1097 _GL_CXXALIASWARN (strstr);
1098 # endif
1099 #elif defined GNULIB_POSIXCHECK
1100 /* strstr() does not work with multibyte strings if the locale encoding is
1101 different from UTF-8:
1102 POSIX says that it operates on "strings", and "string" in POSIX is defined
1103 as a sequence of bytes, not of characters. */
1104 # undef strstr
1105 /* Assume strstr is always declared. */
1106 _GL_WARN_ON_USE_CXX (strstr,
1107 const char *, char *, (const char *, const char *),
1108 "strstr is quadratic on many systems, and cannot "
1109 "work correctly on character strings in most "
1110 "multibyte locales - "
1111 "use mbsstr if you care about internationalization, "
1112 "or use strstr if you care about speed");
1113 #endif
1114
1115 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
1116 comparison. */
1117 #if @GNULIB_STRCASESTR@
1118 # if @REPLACE_STRCASESTR@
1119 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1120 # define strcasestr rpl_strcasestr
1121 # endif
1122 _GL_FUNCDECL_RPL (strcasestr, char *,
1123 (const char *haystack, const char *needle),
1124 _GL_ATTRIBUTE_PURE
1125 _GL_ARG_NONNULL ((1, 2)));
1126 _GL_CXXALIAS_RPL (strcasestr, char *,
1127 (const char *haystack, const char *needle));
1128 # else
1129 # if ! @HAVE_STRCASESTR@
1130 _GL_FUNCDECL_SYS (strcasestr, char *,
1131 (const char *haystack, const char *needle),
1132 _GL_ATTRIBUTE_PURE
1133 _GL_ARG_NONNULL ((1, 2)));
1134 # endif
1135 /* On some systems, this function is defined as an overloaded function:
1136 extern "C++" { const char * strcasestr (const char *, const char *); }
1137 extern "C++" { char * strcasestr (char *, const char *); } */
1138 _GL_CXXALIAS_SYS_CAST2 (strcasestr,
1139 char *, (const char *haystack, const char *needle),
1140 const char *, (const char *haystack, const char *needle));
1141 # endif
1142 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
1143 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
1144 || defined __clang__)
1145 _GL_CXXALIASWARN1 (strcasestr, char *,
1146 (char *haystack, const char *needle)
1147 _GL_ATTRIBUTE_NOTHROW);
1148 _GL_CXXALIASWARN1 (strcasestr, const char *,
1149 (const char *haystack, const char *needle)
1150 _GL_ATTRIBUTE_NOTHROW);
1151 # elif __GLIBC__ >= 2
1152 _GL_CXXALIASWARN (strcasestr);
1153 # endif
1154 #elif defined GNULIB_POSIXCHECK
1155 /* strcasestr() does not work with multibyte strings:
1156 It is a glibc extension, and glibc implements it only for unibyte
1157 locales. */
1158 # if HAVE_RAW_DECL_STRCASESTR
1159 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
1160 "strings in multibyte locales - "
1161 "use mbscasestr if you care about "
1162 "internationalization, or use c-strcasestr if you want "
1163 "a locale independent function");
1164 # endif
1165 #endif
1166
1167 /* Parse S into tokens separated by characters in DELIM.
1168 If S is NULL, the saved pointer in SAVE_PTR is used as
1169 the next starting point. For example:
1170 char s[] = "-abc-=-def";
1171 char *sp;
1172 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1173 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1174 x = strtok_r(NULL, "=", &sp); // x = NULL
1175 // s = "abc\0-def\0"
1176
1177 This is a variant of strtok() that is multithread-safe.
1178
1179 For the POSIX documentation for this function, see:
1180 https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html
1181
1182 Caveat: It modifies the original string.
1183 Caveat: These functions cannot be used on constant strings.
1184 Caveat: The identity of the delimiting character is lost.
1185 Caveat: It doesn't work with multibyte strings unless all of the delimiter
1186 characters are ASCII characters < 0x30.
1187
1188 See also strsep(). */
1189 #if @GNULIB_STRTOK_R@
1190 # if @REPLACE_STRTOK_R@
1191 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1192 # undef strtok_r
1193 # define strtok_r rpl_strtok_r
1194 # endif
1195 _GL_FUNCDECL_RPL (strtok_r, char *,
1196 (char *restrict s, char const *restrict delim,
1197 char **restrict save_ptr),
1198 _GL_ARG_NONNULL ((2, 3)));
1199 _GL_CXXALIAS_RPL (strtok_r, char *,
1200 (char *restrict s, char const *restrict delim,
1201 char **restrict save_ptr));
1202 # else
1203 # if @UNDEFINE_STRTOK_R@
1204 # undef strtok_r
1205 # endif
1206 # if ! @HAVE_DECL_STRTOK_R@
1207 _GL_FUNCDECL_SYS (strtok_r, char *,
1208 (char *restrict s, char const *restrict delim,
1209 char **restrict save_ptr),
1210 _GL_ARG_NONNULL ((2, 3)));
1211 # endif
1212 _GL_CXXALIAS_SYS (strtok_r, char *,
1213 (char *restrict s, char const *restrict delim,
1214 char **restrict save_ptr));
1215 # endif
1216 _GL_CXXALIASWARN (strtok_r);
1217 # if defined GNULIB_POSIXCHECK
1218 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
1219 "strings in multibyte locales - "
1220 "use mbstok_r if you care about internationalization");
1221 # endif
1222 #elif defined GNULIB_POSIXCHECK
1223 # if HAVE_RAW_DECL_STRTOK_R
1224 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
1225 "use gnulib module strtok_r for portability");
1226 # endif
1227 #endif
1228
1229
1230 /* The following functions are not specified by POSIX. They are gnulib
1231 extensions. */
1232
1233 #if @GNULIB_STR_STARTSWITH@
1234 /* Returns true if STRING starts with PREFIX.
1235 Returns false otherwise. */
1236 _GL_EXTERN_C bool str_startswith (const char *string, const char *prefix)
1237 _GL_ATTRIBUTE_PURE
1238 _GL_ARG_NONNULL ((1, 2));
1239 #endif
1240
1241 #if @GNULIB_STR_ENDSWITH@
1242 /* Returns true if STRING ends with SUFFIX.
1243 Returns false otherwise. */
1244 _GL_EXTERN_C bool str_endswith (const char *string, const char *prefix)
1245 _GL_ATTRIBUTE_PURE
1246 _GL_ARG_NONNULL ((1, 2));
1247 #endif
1248
1249 #if @GNULIB_MBSLEN@
1250 /* Return the number of multibyte characters in the character string STRING.
1251 This considers multibyte characters, unlike strlen, which counts bytes. */
1252 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
1253 # undef mbslen
1254 # endif
1255 # if @HAVE_MBSLEN@ /* AIX, MirBSD define mbslen already in libc. */
1256 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1257 # define mbslen rpl_mbslen
1258 # endif
1259 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string),
1260 _GL_ATTRIBUTE_PURE
1261 _GL_ARG_NONNULL ((1)));
1262 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
1263 # else
1264 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string),
1265 _GL_ATTRIBUTE_PURE
1266 _GL_ARG_NONNULL ((1)));
1267 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
1268 # endif
1269 # if __GLIBC__ >= 2
1270 _GL_CXXALIASWARN (mbslen);
1271 # endif
1272 #endif
1273
1274 #if @GNULIB_MBSNLEN@
1275 /* Return the number of multibyte characters in the character string starting
1276 at STRING and ending at STRING + LEN. */
1277 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
1278 _GL_ATTRIBUTE_PURE
1279 _GL_ARG_NONNULL ((1));
1280 #endif
1281
1282 #if @GNULIB_MBSCHR@
1283 /* Locate the first single-byte character C in the character string STRING,
1284 and return a pointer to it. Return NULL if C is not found in STRING.
1285 Unlike strchr(), this function works correctly in multibyte locales with
1286 encodings such as GB18030. */
1287 # if defined __hpux
1288 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1289 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
1290 # endif
1291 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c),
1292 _GL_ATTRIBUTE_PURE
1293 _GL_ARG_NONNULL ((1)));
1294 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
1295 # else
1296 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c),
1297 _GL_ATTRIBUTE_PURE
1298 _GL_ARG_NONNULL ((1)));
1299 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
1300 # endif
1301 _GL_CXXALIASWARN (mbschr);
1302 #endif
1303
1304 #if @GNULIB_MBSRCHR@
1305 /* Locate the last single-byte character C in the character string STRING,
1306 and return a pointer to it. Return NULL if C is not found in STRING.
1307 Unlike strrchr(), this function works correctly in multibyte locales with
1308 encodings such as GB18030. */
1309 # if defined __hpux || defined __INTERIX
1310 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1311 # define mbsrchr rpl_mbsrchr /* avoid collision with system function */
1312 # endif
1313 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c),
1314 _GL_ATTRIBUTE_PURE
1315 _GL_ARG_NONNULL ((1)));
1316 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
1317 # else
1318 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c),
1319 _GL_ATTRIBUTE_PURE
1320 _GL_ARG_NONNULL ((1)));
1321 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
1322 # endif
1323 _GL_CXXALIASWARN (mbsrchr);
1324 #endif
1325
1326 #if @GNULIB_MBSSTR@
1327 /* Find the first occurrence of the character string NEEDLE in the character
1328 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
1329 Unlike strstr(), this function works correctly in multibyte locales with
1330 encodings different from UTF-8. */
1331 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
1332 _GL_ATTRIBUTE_PURE
1333 _GL_ARG_NONNULL ((1, 2));
1334 # ifndef _GL_NO_CONST_GENERICS
1335 /* Don't silently convert a 'const char *' to a 'char *'. Programmers want
1336 compiler warnings for 'const' related mistakes. */
1337 # ifdef __cplusplus
1338 extern "C++" { /* needed for AIX */
1339 template <typename T>
1340 T * mbsstr_template (T* haystack, const char *needle);
1341 template <>
1342 inline char * mbsstr_template (char *haystack, const char *needle)
1343 { return mbsstr (haystack, needle); }
1344 template <>
1345 inline const char * mbsstr_template (const char *haystack, const char *needle)
1346 { return mbsstr (haystack, needle); }
1347 }
1348 # undef mbsstr
1349 # define mbsstr mbsstr_template
1350 # elif !defined mbsstr
1351 # if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
1352 || defined __ICC || defined __TINYC__ \
1353 || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
1354 # define mbsstr(h,n) \
1355 _Generic ((h), \
1356 char const *: (char const *) mbsstr ((h), (n)), \
1357 default : mbsstr ((h), (n)))
1358 # endif
1359 # endif
1360 # endif
1361 #endif
1362
1363 #if @GNULIB_MBSCASECMP@
1364 /* Compare the character strings S1 and S2, ignoring case, returning less than,
1365 equal to or greater than zero if S1 is lexicographically less than, equal to
1366 or greater than S2.
1367 Note: This function may, in multibyte locales, return 0 for strings of
1368 different lengths!
1369 Unlike strcasecmp(), this function works correctly in multibyte locales. */
1370 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
1371 _GL_ATTRIBUTE_PURE
1372 _GL_ARG_NONNULL ((1, 2));
1373 #endif
1374
1375 #if @GNULIB_MBSNCASECMP@
1376 /* Compare the initial segment of the character string S1 consisting of at most
1377 N characters with the initial segment of the character string S2 consisting
1378 of at most N characters, ignoring case, returning less than, equal to or
1379 greater than zero if the initial segment of S1 is lexicographically less
1380 than, equal to or greater than the initial segment of S2.
1381 Note: This function may, in multibyte locales, return 0 for initial segments
1382 of different lengths!
1383 Unlike strncasecmp(), this function works correctly in multibyte locales.
1384 But beware that N is not a byte count but a character count! */
1385 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
1386 _GL_ATTRIBUTE_PURE
1387 _GL_ARG_NONNULL ((1, 2));
1388 #endif
1389
1390 #if @GNULIB_MBSPCASECMP@
1391 /* Compare the initial segment of the character string STRING consisting of
1392 at most mbslen (PREFIX) characters with the character string PREFIX,
1393 ignoring case. If the two match, return a pointer to the first byte
1394 after this prefix in STRING. Otherwise, return NULL.
1395 Note: This function may, in multibyte locales, return non-NULL if STRING
1396 is of smaller length than PREFIX!
1397 Unlike strncasecmp(), this function works correctly in multibyte
1398 locales. */
1399 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
1400 _GL_ATTRIBUTE_PURE
1401 _GL_ARG_NONNULL ((1, 2));
1402 # ifndef _GL_NO_CONST_GENERICS
1403 /* Don't silently convert a 'const char *' to a 'char *'. Programmers want
1404 compiler warnings for 'const' related mistakes. */
1405 # ifdef __cplusplus
1406 extern "C++" { /* needed for AIX */
1407 template <typename T>
1408 T * mbspcasecmp_template (T* string, const char *prefix);
1409 template <>
1410 inline char * mbspcasecmp_template (char *string, const char *prefix)
1411 { return mbspcasecmp (string, prefix); }
1412 template <>
1413 inline const char * mbspcasecmp_template (const char *string, const char *prefix)
1414 { return mbspcasecmp (string, prefix); }
1415 }
1416 # undef mbspcasecmp
1417 # define mbspcasecmp mbspcasecmp_template
1418 # elif !defined mbspcasecmp
1419 # if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
1420 || defined __ICC || defined __TINYC__ \
1421 || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
1422 # define mbspcasecmp(s,p) \
1423 _Generic ((s), \
1424 char const *: (char const *) mbspcasecmp ((s), (p)), \
1425 default : mbspcasecmp ((s), (p)))
1426 # endif
1427 # endif
1428 # endif
1429 #endif
1430
1431 #if @GNULIB_MBSCASESTR@
1432 /* Find the first occurrence of the character string NEEDLE in the character
1433 string HAYSTACK, using case-insensitive comparison.
1434 Note: This function may, in multibyte locales, return success even if
1435 strlen (haystack) < strlen (needle) !
1436 Unlike strcasestr(), this function works correctly in multibyte locales. */
1437 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
1438 _GL_ATTRIBUTE_PURE
1439 _GL_ARG_NONNULL ((1, 2));
1440 # ifndef _GL_NO_CONST_GENERICS
1441 /* Don't silently convert a 'const char *' to a 'char *'. Programmers want
1442 compiler warnings for 'const' related mistakes. */
1443 # ifdef __cplusplus
1444 extern "C++" { /* needed for AIX */
1445 template <typename T>
1446 T * mbscasestr_template (T* haystack, const char *needle);
1447 template <>
1448 inline char * mbscasestr_template (char *haystack, const char *needle)
1449 { return mbscasestr (haystack, needle); }
1450 template <>
1451 inline const char * mbscasestr_template (const char *haystack, const char *needle)
1452 { return mbscasestr (haystack, needle); }
1453 }
1454 # undef mbscasestr
1455 # define mbscasestr mbscasestr_template
1456 # elif !defined mbscasestr
1457 # if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
1458 || defined __ICC || defined __TINYC__ \
1459 || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
1460 # define mbscasestr(h,n) \
1461 _Generic ((h), \
1462 char const *: (char const *) mbscasestr ((h), (n)), \
1463 default : mbscasestr ((h), (n)))
1464 # endif
1465 # endif
1466 # endif
1467 #endif
1468
1469 #if @GNULIB_MBSCSPN@
1470 /* Find the first occurrence in the character string STRING of any character
1471 in the character string ACCEPT. Return the number of bytes from the
1472 beginning of the string to this occurrence, or to the end of the string
1473 if none exists.
1474 Unlike strcspn(), this function works correctly in multibyte locales. */
1475 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
1476 _GL_ATTRIBUTE_PURE
1477 _GL_ARG_NONNULL ((1, 2));
1478 #endif
1479
1480 #if @GNULIB_MBSPBRK@
1481 /* Find the first occurrence in the character string STRING of any character
1482 in the character string ACCEPT. Return the pointer to it, or NULL if none
1483 exists.
1484 Unlike strpbrk(), this function works correctly in multibyte locales. */
1485 # if defined __hpux
1486 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1487 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1488 # endif
1489 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept),
1490 _GL_ATTRIBUTE_PURE
1491 _GL_ARG_NONNULL ((1, 2)));
1492 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
1493 # else
1494 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept),
1495 _GL_ATTRIBUTE_PURE
1496 _GL_ARG_NONNULL ((1, 2)));
1497 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
1498 # endif
1499 _GL_CXXALIASWARN (mbspbrk);
1500 #endif
1501
1502 #if @GNULIB_MBSSPN@
1503 /* Find the first occurrence in the character string STRING of any character
1504 not in the character string REJECT. Return the number of bytes from the
1505 beginning of the string to this occurrence, or to the end of the string
1506 if none exists.
1507 Unlike strspn(), this function works correctly in multibyte locales. */
1508 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
1509 _GL_ATTRIBUTE_PURE
1510 _GL_ARG_NONNULL ((1, 2));
1511 #endif
1512
1513 #if @GNULIB_MBSSEP@
1514 /* Search the next delimiter (multibyte character listed in the character
1515 string DELIM) starting at the character string *STRINGP.
1516 If one is found, overwrite it with a NUL, and advance *STRINGP to point
1517 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
1518 If *STRINGP was already NULL, nothing happens.
1519 Return the old value of *STRINGP.
1520
1521 This is a variant of mbstok_r() that supports empty fields.
1522
1523 Caveat: It modifies the original string.
1524 Caveat: These functions cannot be used on constant strings.
1525 Caveat: The identity of the delimiting character is lost.
1526
1527 See also mbstok_r(). */
1528 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
1529 _GL_ARG_NONNULL ((1, 2));
1530 #endif
1531
1532 #if @GNULIB_MBSTOK_R@
1533 /* Parse the character string STRING into tokens separated by characters in
1534 the character string DELIM.
1535 If STRING is NULL, the saved pointer in SAVE_PTR is used as
1536 the next starting point. For example:
1537 char s[] = "-abc-=-def";
1538 char *sp;
1539 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1540 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1541 x = mbstok_r(NULL, "=", &sp); // x = NULL
1542 // s = "abc\0-def\0"
1543
1544 Caveat: It modifies the original string.
1545 Caveat: These functions cannot be used on constant strings.
1546 Caveat: The identity of the delimiting character is lost.
1547
1548 See also mbssep(). */
1549 _GL_EXTERN_C char * mbstok_r (char *restrict string, const char *delim,
1550 char **save_ptr)
1551 _GL_ARG_NONNULL ((2, 3));
1552 #endif
1553
1554 #if @GNULIB_MBS_STARTSWITH@
1555 /* Returns true if STRING starts with PREFIX.
1556 Returns false otherwise. */
1557 _GL_EXTERN_C bool mbs_startswith (const char *string, const char *prefix)
1558 _GL_ATTRIBUTE_PURE
1559 _GL_ARG_NONNULL ((1, 2));
1560 #endif
1561
1562 #if @GNULIB_MBS_ENDSWITH@
1563 /* Returns true if STRING ends with SUFFIX.
1564 Returns false otherwise.
1565 Unlike str_endswith(), this function works correctly in multibyte locales.
1566 */
1567 _GL_EXTERN_C bool mbs_endswith (const char *string, const char *suffix)
1568 _GL_ATTRIBUTE_PURE
1569 _GL_ARG_NONNULL ((1, 2));
1570 #endif
1571
1572 /* Map any int, typically from errno, into an error message. */
1573 #if @GNULIB_STRERROR@
1574 # if @REPLACE_STRERROR@
1575 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1576 # undef strerror
1577 # define strerror rpl_strerror
1578 # endif
1579 _GL_FUNCDECL_RPL (strerror, char *, (int), );
1580 _GL_CXXALIAS_RPL (strerror, char *, (int));
1581 # else
1582 _GL_CXXALIAS_SYS (strerror, char *, (int));
1583 # endif
1584 # if __GLIBC__ >= 2
1585 _GL_CXXALIASWARN (strerror);
1586 # endif
1587 #elif defined GNULIB_POSIXCHECK
1588 /* Assume strerror is always declared. */
1589 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
1590 "use gnulib module strerror to guarantee non-NULL result");
1591 #endif
1592
1593 /* Map any int, typically from errno, into an error message. Multithread-safe.
1594 Uses the POSIX declaration, not the glibc declaration. */
1595 #if @GNULIB_STRERROR_R@
1596 # if @REPLACE_STRERROR_R@
1597 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1598 # undef strerror_r
1599 # define strerror_r rpl_strerror_r
1600 # endif
1601 _GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen),
1602 _GL_ARG_NONNULL ((2)));
1603 _GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
1604 # else
1605 # if !@HAVE_DECL_STRERROR_R@
1606 _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen),
1607 _GL_ARG_NONNULL ((2)));
1608 # endif
1609 _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
1610 # endif
1611 # if __GLIBC__ >= 2 && @HAVE_DECL_STRERROR_R@
1612 _GL_CXXALIASWARN (strerror_r);
1613 # endif
1614 #elif defined GNULIB_POSIXCHECK
1615 # if HAVE_RAW_DECL_STRERROR_R
1616 _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
1617 "use gnulib module strerror_r-posix for portability");
1618 # endif
1619 #endif
1620
1621 /* Map any int, typically from errno, into an error message.
1622 With locale_t argument. */
1623 #if @GNULIB_STRERROR_L@
1624 # if @REPLACE_STRERROR_L@
1625 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1626 # undef strerror_l
1627 # define strerror_l rpl_strerror_l
1628 # endif
1629 _GL_FUNCDECL_RPL (strerror_l, char *, (int errnum, locale_t locale),
1630 _GL_ARG_NONNULL ((2)));
1631 _GL_CXXALIAS_RPL (strerror_l, char *, (int errnum, locale_t locale));
1632 # else
1633 # if !@HAVE_STRERROR_L@
1634 _GL_FUNCDECL_SYS (strerror_l, char *, (int errnum, locale_t locale),
1635 _GL_ARG_NONNULL ((2)));
1636 # endif
1637 _GL_CXXALIAS_SYS (strerror_l, char *, (int errnum, locale_t locale));
1638 # endif
1639 # if __GLIBC__ >= 2
1640 _GL_CXXALIASWARN (strerror_l);
1641 # endif
1642 #elif defined GNULIB_POSIXCHECK
1643 # if HAVE_RAW_DECL_STRERROR_L
1644 _GL_WARN_ON_USE (strerror_l, "strerror_l is unportable - "
1645 "use gnulib module strerror_l for portability");
1646 # endif
1647 #endif
1648
1649 /* Map any int, typically from errno, into an error message. Multithread-safe,
1650 with locale_t argument.
1651 Not portable! Only provided by gnulib. */
1652 #if @GNULIB_STRERROR_L@
1653 _GL_FUNCDECL_SYS (strerror_l_r, int,
1654 (int errnum, char *buf, size_t buflen, locale_t locale),
1655 _GL_ARG_NONNULL ((2, 4)));
1656 #endif
1657
1658 /* Return the name of the system error code ERRNUM. */
1659 #if @GNULIB_STRERRORNAME_NP@
1660 # if @REPLACE_STRERRORNAME_NP@
1661 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1662 # undef strerrorname_np
1663 # define strerrorname_np rpl_strerrorname_np
1664 # endif
1665 _GL_FUNCDECL_RPL (strerrorname_np, const char *, (int errnum), );
1666 _GL_CXXALIAS_RPL (strerrorname_np, const char *, (int errnum));
1667 # else
1668 # if !@HAVE_STRERRORNAME_NP@
1669 _GL_FUNCDECL_SYS (strerrorname_np, const char *, (int errnum), );
1670 # endif
1671 _GL_CXXALIAS_SYS (strerrorname_np, const char *, (int errnum));
1672 # endif
1673 # if __GLIBC__ >= 2
1674 _GL_CXXALIASWARN (strerrorname_np);
1675 # endif
1676 #elif defined GNULIB_POSIXCHECK
1677 # if HAVE_RAW_DECL_STRERRORNAME_NP
1678 _GL_WARN_ON_USE (strerrorname_np, "strerrorname_np is unportable - "
1679 "use gnulib module strerrorname_np for portability");
1680 # endif
1681 #endif
1682
1683 /* Return an abbreviation string for the signal number SIG. */
1684 #if @GNULIB_SIGABBREV_NP@
1685 # if ! @HAVE_SIGABBREV_NP@
1686 _GL_FUNCDECL_SYS (sigabbrev_np, const char *, (int sig), );
1687 # endif
1688 _GL_CXXALIAS_SYS (sigabbrev_np, const char *, (int sig));
1689 _GL_CXXALIASWARN (sigabbrev_np);
1690 #elif defined GNULIB_POSIXCHECK
1691 # if HAVE_RAW_DECL_SIGABBREV_NP
1692 _GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - "
1693 "use gnulib module sigabbrev_np for portability");
1694 # endif
1695 #endif
1696
1697 /* Return an English description string for the signal number SIG. */
1698 #if @GNULIB_SIGDESCR_NP@
1699 # if ! @HAVE_SIGDESCR_NP@
1700 _GL_FUNCDECL_SYS (sigdescr_np, const char *, (int sig), );
1701 # endif
1702 _GL_CXXALIAS_SYS (sigdescr_np, const char *, (int sig));
1703 _GL_CXXALIASWARN (sigdescr_np);
1704 #elif defined GNULIB_POSIXCHECK
1705 # if HAVE_RAW_DECL_SIGDESCR_NP
1706 _GL_WARN_ON_USE (sigdescr_np, "sigdescr_np is unportable - "
1707 "use gnulib module sigdescr_np for portability");
1708 # endif
1709 #endif
1710
1711 #if @GNULIB_STRSIGNAL@
1712 # if @REPLACE_STRSIGNAL@
1713 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1714 # define strsignal rpl_strsignal
1715 # endif
1716 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig), );
1717 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
1718 # else
1719 # if ! @HAVE_DECL_STRSIGNAL@
1720 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig), );
1721 # endif
1722 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
1723 'const char *'. */
1724 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
1725 # endif
1726 _GL_CXXALIASWARN (strsignal);
1727 #elif defined GNULIB_POSIXCHECK
1728 # if HAVE_RAW_DECL_STRSIGNAL
1729 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
1730 "use gnulib module strsignal for portability");
1731 # endif
1732 #endif
1733
1734 #if @GNULIB_STRVERSCMP@
1735 # if @REPLACE_STRVERSCMP@
1736 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1737 # define strverscmp rpl_strverscmp
1738 # endif
1739 _GL_FUNCDECL_RPL (strverscmp, int, (const char *, const char *),
1740 _GL_ATTRIBUTE_PURE
1741 _GL_ARG_NONNULL ((1, 2)));
1742 _GL_CXXALIAS_RPL (strverscmp, int, (const char *, const char *));
1743 # else
1744 # if !@HAVE_STRVERSCMP@
1745 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *),
1746 _GL_ATTRIBUTE_PURE
1747 _GL_ARG_NONNULL ((1, 2)));
1748 # endif
1749 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
1750 # endif
1751 _GL_CXXALIASWARN (strverscmp);
1752 #elif defined GNULIB_POSIXCHECK
1753 # if HAVE_RAW_DECL_STRVERSCMP
1754 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1755 "use gnulib module strverscmp for portability");
1756 # endif
1757 #endif
1758
1759 _GL_INLINE_HEADER_END
1760
1761 #endif /* _@GUARD_PREFIX@_STRING_H */
1762 #endif /* _@GUARD_PREFIX@_STRING_H */
1763 #endif