1 /* A GNU-like <string.h>.
2
3 Copyright (C) 1995-1996, 2001-2023 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 _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. */
29
30 #@INCLUDE_NEXT@ @NEXT_STRING_H@
31
32 #else
33 /* Normal invocation convention. */
34
35 #ifndef _@GUARD_PREFIX@_STRING_H
36
37 #define _GL_ALREADY_INCLUDING_STRING_H
38
39 /* The include_next requires a split double-inclusion guard. */
40 #@INCLUDE_NEXT@ @NEXT_STRING_H@
41
42 #undef _GL_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 /* MirBSD defines mbslen as a macro. */
58 #if @GNULIB_MBSLEN@ && defined __MirBSD__
59 # include <wchar.h>
60 #endif
61
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
68
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
77
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
88
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
102
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
113
114 /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
115 */
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
135
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
145
146 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
147
148 /* The definition of _GL_ARG_NONNULL is copied here. */
149
150 /* The definition of _GL_WARN_ON_USE is copied here. */
151
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
195
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
212
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
226
227
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
249
250
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
268
269
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
307
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
343
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
380
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
413
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 ! @HAVE_MEMSET_EXPLICIT@
418 _GL_FUNCDECL_SYS (memset_explicit, void *,
419 (void *__dest, int __c, size_t __n) _GL_ARG_NONNULL ((1)));
420 # endif
421 _GL_CXXALIAS_SYS (memset_explicit, void *, (void *__dest, int __c, size_t __n));
422 _GL_CXXALIASWARN (memset_explicit);
423 #elif defined GNULIB_POSIXCHECK
424 # undef memset_explicit
425 # if HAVE_RAW_DECL_MEMSET_EXPLICIT
426 _GL_WARN_ON_USE (memset_explicit, "memset_explicit is unportable - "
427 "use gnulib module memset_explicit for portability");
428 # endif
429 #endif
430
431 /* Find the first occurrence of C in S. More efficient than
432 memchr(S,C,N), at the expense of undefined behavior if C does not
433 occur within N bytes. */
434 #if @GNULIB_RAWMEMCHR@
435 # if ! @HAVE_RAWMEMCHR@
436 _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
437 _GL_ATTRIBUTE_PURE
438 _GL_ARG_NONNULL ((1)));
439 # endif
440 /* On some systems, this function is defined as an overloaded function:
441 extern "C++" { const void * std::rawmemchr (const void *, int); }
442 extern "C++" { void * std::rawmemchr (void *, int); } */
443 _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
444 void *, (void const *__s, int __c_in),
445 void const *, (void const *__s, int __c_in));
446 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
447 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
448 || defined __clang__)
449 _GL_CXXALIASWARN1 (rawmemchr, void *,
450 (void *__s, int __c_in)
451 _GL_ATTRIBUTE_NOTHROW);
452 _GL_CXXALIASWARN1 (rawmemchr, void const *,
453 (void const *__s, int __c_in)
454 _GL_ATTRIBUTE_NOTHROW);
455 # else
456 _GL_CXXALIASWARN (rawmemchr);
457 # endif
458 #elif defined GNULIB_POSIXCHECK
459 # undef rawmemchr
460 # if HAVE_RAW_DECL_RAWMEMCHR
461 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
462 "use gnulib module rawmemchr for portability");
463 # endif
464 #endif
465
466 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
467 #if @GNULIB_STPCPY@
468 # if @REPLACE_STPCPY@
469 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
470 # undef stpcpy
471 # define stpcpy rpl_stpcpy
472 # endif
473 _GL_FUNCDECL_RPL (stpcpy, char *,
474 (char *restrict __dst, char const *restrict __src)
475 _GL_ARG_NONNULL ((1, 2)));
476 _GL_CXXALIAS_RPL (stpcpy, char *,
477 (char *restrict __dst, char const *restrict __src));
478 # else
479 # if !@HAVE_STPCPY@
480 _GL_FUNCDECL_SYS (stpcpy, char *,
481 (char *restrict __dst, char const *restrict __src)
482 _GL_ARG_NONNULL ((1, 2)));
483 # endif
484 _GL_CXXALIAS_SYS (stpcpy, char *,
485 (char *restrict __dst, char const *restrict __src));
486 # endif
487 # if __GLIBC__ >= 2
488 _GL_CXXALIASWARN (stpcpy);
489 # endif
490 #elif defined GNULIB_POSIXCHECK
491 # undef stpcpy
492 # if HAVE_RAW_DECL_STPCPY
493 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
494 "use gnulib module stpcpy for portability");
495 # endif
496 #endif
497
498 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
499 last non-NUL byte written into DST. */
500 #if @GNULIB_STPNCPY@
501 # if @REPLACE_STPNCPY@
502 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
503 # undef stpncpy
504 # define stpncpy rpl_stpncpy
505 # endif
506 _GL_FUNCDECL_RPL (stpncpy, char *,
507 (char *restrict __dst, char const *restrict __src,
508 size_t __n)
509 _GL_ARG_NONNULL ((1, 2)));
510 _GL_CXXALIAS_RPL (stpncpy, char *,
511 (char *restrict __dst, char const *restrict __src,
512 size_t __n));
513 # else
514 # if ! @HAVE_STPNCPY@
515 _GL_FUNCDECL_SYS (stpncpy, char *,
516 (char *restrict __dst, char const *restrict __src,
517 size_t __n)
518 _GL_ARG_NONNULL ((1, 2)));
519 # endif
520 _GL_CXXALIAS_SYS (stpncpy, char *,
521 (char *restrict __dst, char const *restrict __src,
522 size_t __n));
523 # endif
524 # if __GLIBC__ >= 2
525 _GL_CXXALIASWARN (stpncpy);
526 # endif
527 #elif defined GNULIB_POSIXCHECK
528 # undef stpncpy
529 # if HAVE_RAW_DECL_STPNCPY
530 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
531 "use gnulib module stpncpy for portability");
532 # endif
533 #endif
534
535 #if defined GNULIB_POSIXCHECK
536 /* strchr() does not work with multibyte strings if the locale encoding is
537 GB18030 and the character to be searched is a digit. */
538 # undef strchr
539 /* Assume strchr is always declared. */
540 _GL_WARN_ON_USE_CXX (strchr,
541 const char *, char *, (const char *, int),
542 "strchr cannot work correctly on character strings "
543 "in some multibyte locales - "
544 "use mbschr if you care about internationalization");
545 #endif
546
547 /* Find the first occurrence of C in S or the final NUL byte. */
548 #if @GNULIB_STRCHRNUL@
549 # if @REPLACE_STRCHRNUL@
550 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
551 # define strchrnul rpl_strchrnul
552 # endif
553 _GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in)
554 _GL_ATTRIBUTE_PURE
555 _GL_ARG_NONNULL ((1)));
556 _GL_CXXALIAS_RPL (strchrnul, char *,
557 (const char *str, int ch));
558 # else
559 # if ! @HAVE_STRCHRNUL@
560 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
561 _GL_ATTRIBUTE_PURE
562 _GL_ARG_NONNULL ((1)));
563 # endif
564 /* On some systems, this function is defined as an overloaded function:
565 extern "C++" { const char * std::strchrnul (const char *, int); }
566 extern "C++" { char * std::strchrnul (char *, int); } */
567 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
568 char *, (char const *__s, int __c_in),
569 char const *, (char const *__s, int __c_in));
570 # endif
571 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
572 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
573 || defined __clang__)
574 _GL_CXXALIASWARN1 (strchrnul, char *,
575 (char *__s, int __c_in)
576 _GL_ATTRIBUTE_NOTHROW);
577 _GL_CXXALIASWARN1 (strchrnul, char const *,
578 (char const *__s, int __c_in)
579 _GL_ATTRIBUTE_NOTHROW);
580 # elif __GLIBC__ >= 2
581 _GL_CXXALIASWARN (strchrnul);
582 # endif
583 #elif defined GNULIB_POSIXCHECK
584 # undef strchrnul
585 # if HAVE_RAW_DECL_STRCHRNUL
586 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
587 "use gnulib module strchrnul for portability");
588 # endif
589 #endif
590
591 /* Duplicate S, returning an identical malloc'd string. */
592 #if @GNULIB_STRDUP@
593 # if @REPLACE_STRDUP@
594 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
595 # undef strdup
596 # define strdup rpl_strdup
597 # endif
598 _GL_FUNCDECL_RPL (strdup, char *,
599 (char const *__s)
600 _GL_ARG_NONNULL ((1))
601 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
602 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
603 # elif defined _WIN32 && !defined __CYGWIN__
604 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
605 # undef strdup
606 # define strdup _strdup
607 # endif
608 _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
609 # else
610 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
611 /* strdup exists as a function and as a macro. Get rid of the macro. */
612 # undef strdup
613 # endif
614 # if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup
615 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
616 _GL_FUNCDECL_SYS (strdup, char *,
617 (char const *__s)
618 _GL_ATTRIBUTE_NOTHROW
619 _GL_ARG_NONNULL ((1))
620 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
621 # else
622 _GL_FUNCDECL_SYS (strdup, char *,
623 (char const *__s)
624 _GL_ARG_NONNULL ((1))
625 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
626 # endif
627 # endif
628 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
629 # endif
630 _GL_CXXALIASWARN (strdup);
631 #else
632 # if __GNUC__ >= 11 && !defined strdup
633 /* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */
634 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
635 _GL_FUNCDECL_SYS (strdup, char *,
636 (char const *__s)
637 _GL_ATTRIBUTE_NOTHROW
638 _GL_ARG_NONNULL ((1))
639 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
640 # else
641 _GL_FUNCDECL_SYS (strdup, char *,
642 (char const *__s)
643 _GL_ARG_NONNULL ((1))
644 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
645 # endif
646 # endif
647 # if defined GNULIB_POSIXCHECK
648 # undef strdup
649 # if HAVE_RAW_DECL_STRDUP
650 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
651 "use gnulib module strdup for portability");
652 # endif
653 # elif @GNULIB_MDA_STRDUP@
654 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
655 required. In C++ with GNULIB_NAMESPACE, avoid differences between
656 platforms by defining GNULIB_NAMESPACE::strdup always. */
657 # if defined _WIN32 && !defined __CYGWIN__
658 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
659 # undef strdup
660 # define strdup _strdup
661 # endif
662 _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
663 # else
664 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
665 # undef strdup
666 # endif
667 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
668 # endif
669 _GL_CXXALIASWARN (strdup);
670 # endif
671 #endif
672
673 /* Append no more than N characters from SRC onto DEST. */
674 #if @GNULIB_STRNCAT@
675 # if @REPLACE_STRNCAT@
676 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
677 # undef strncat
678 # define strncat rpl_strncat
679 # endif
680 _GL_FUNCDECL_RPL (strncat, char *,
681 (char *restrict dest, const char *restrict src, size_t n)
682 _GL_ARG_NONNULL ((1, 2)));
683 _GL_CXXALIAS_RPL (strncat, char *,
684 (char *restrict dest, const char *restrict src, size_t n));
685 # else
686 _GL_CXXALIAS_SYS (strncat, char *,
687 (char *restrict dest, const char *restrict src, size_t n));
688 # endif
689 # if __GLIBC__ >= 2
690 _GL_CXXALIASWARN (strncat);
691 # endif
692 #elif defined GNULIB_POSIXCHECK
693 # undef strncat
694 # if HAVE_RAW_DECL_STRNCAT
695 _GL_WARN_ON_USE (strncat, "strncat is unportable - "
696 "use gnulib module strncat for portability");
697 # endif
698 #endif
699
700 /* Return a newly allocated copy of at most N bytes of STRING. */
701 #if @GNULIB_STRNDUP@
702 # if @REPLACE_STRNDUP@
703 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
704 # undef strndup
705 # define strndup rpl_strndup
706 # endif
707 _GL_FUNCDECL_RPL (strndup, char *,
708 (char const *__s, size_t __n)
709 _GL_ARG_NONNULL ((1))
710 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
711 _GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n));
712 # else
713 # if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined strndup)
714 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
715 _GL_FUNCDECL_SYS (strndup, char *,
716 (char const *__s, size_t __n)
717 _GL_ATTRIBUTE_NOTHROW
718 _GL_ARG_NONNULL ((1))
719 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
720 # else
721 _GL_FUNCDECL_SYS (strndup, char *,
722 (char const *__s, size_t __n)
723 _GL_ARG_NONNULL ((1))
724 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
725 # endif
726 # endif
727 _GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n));
728 # endif
729 _GL_CXXALIASWARN (strndup);
730 #else
731 # if __GNUC__ >= 11 && !defined strndup
732 /* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */
733 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
734 _GL_FUNCDECL_SYS (strndup, char *,
735 (char const *__s, size_t __n)
736 _GL_ATTRIBUTE_NOTHROW
737 _GL_ARG_NONNULL ((1))
738 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
739 # else
740 _GL_FUNCDECL_SYS (strndup, char *,
741 (char const *__s, size_t __n)
742 _GL_ARG_NONNULL ((1))
743 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
744 # endif
745 # endif
746 # if defined GNULIB_POSIXCHECK
747 # undef strndup
748 # if HAVE_RAW_DECL_STRNDUP
749 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
750 "use gnulib module strndup for portability");
751 # endif
752 # endif
753 #endif
754
755 /* Find the length (number of bytes) of STRING, but scan at most
756 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
757 return MAXLEN. */
758 #if @GNULIB_STRNLEN@
759 # if @REPLACE_STRNLEN@
760 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
761 # undef strnlen
762 # define strnlen rpl_strnlen
763 # endif
764 _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen)
765 _GL_ATTRIBUTE_PURE
766 _GL_ARG_NONNULL ((1)));
767 _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen));
768 # else
769 # if ! @HAVE_DECL_STRNLEN@
770 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen)
771 _GL_ATTRIBUTE_PURE
772 _GL_ARG_NONNULL ((1)));
773 # endif
774 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__s, size_t __maxlen));
775 # endif
776 _GL_CXXALIASWARN (strnlen);
777 #elif defined GNULIB_POSIXCHECK
778 # undef strnlen
779 # if HAVE_RAW_DECL_STRNLEN
780 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
781 "use gnulib module strnlen for portability");
782 # endif
783 #endif
784
785 #if defined GNULIB_POSIXCHECK
786 /* strcspn() assumes the second argument is a list of single-byte characters.
787 Even in this simple case, it does not work with multibyte strings if the
788 locale encoding is GB18030 and one of the characters to be searched is a
789 digit. */
790 # undef strcspn
791 /* Assume strcspn is always declared. */
792 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
793 "in multibyte locales - "
794 "use mbscspn if you care about internationalization");
795 #endif
796
797 /* Find the first occurrence in S of any character in ACCEPT. */
798 #if @GNULIB_STRPBRK@
799 # if ! @HAVE_STRPBRK@
800 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
801 _GL_ATTRIBUTE_PURE
802 _GL_ARG_NONNULL ((1, 2)));
803 # endif
804 /* On some systems, this function is defined as an overloaded function:
805 extern "C" { const char * strpbrk (const char *, const char *); }
806 extern "C++" { char * strpbrk (char *, const char *); } */
807 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
808 char *, (char const *__s, char const *__accept),
809 const char *, (char const *__s, char const *__accept));
810 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
811 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
812 || defined __clang__)
813 _GL_CXXALIASWARN1 (strpbrk, char *,
814 (char *__s, char const *__accept)
815 _GL_ATTRIBUTE_NOTHROW);
816 _GL_CXXALIASWARN1 (strpbrk, char const *,
817 (char const *__s, char const *__accept)
818 _GL_ATTRIBUTE_NOTHROW);
819 # elif __GLIBC__ >= 2
820 _GL_CXXALIASWARN (strpbrk);
821 # endif
822 # if defined GNULIB_POSIXCHECK
823 /* strpbrk() assumes the second argument is a list of single-byte characters.
824 Even in this simple case, it does not work with multibyte strings if the
825 locale encoding is GB18030 and one of the characters to be searched is a
826 digit. */
827 # undef strpbrk
828 _GL_WARN_ON_USE_CXX (strpbrk,
829 const char *, char *, (const char *, const char *),
830 "strpbrk cannot work correctly on character strings "
831 "in multibyte locales - "
832 "use mbspbrk if you care about internationalization");
833 # endif
834 #elif defined GNULIB_POSIXCHECK
835 # undef strpbrk
836 # if HAVE_RAW_DECL_STRPBRK
837 _GL_WARN_ON_USE_CXX (strpbrk,
838 const char *, char *, (const char *, const char *),
839 "strpbrk is unportable - "
840 "use gnulib module strpbrk for portability");
841 # endif
842 #endif
843
844 #if defined GNULIB_POSIXCHECK
845 /* strspn() assumes the second argument is a list of single-byte characters.
846 Even in this simple case, it cannot work with multibyte strings. */
847 # undef strspn
848 /* Assume strspn is always declared. */
849 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
850 "in multibyte locales - "
851 "use mbsspn if you care about internationalization");
852 #endif
853
854 #if defined GNULIB_POSIXCHECK
855 /* strrchr() does not work with multibyte strings if the locale encoding is
856 GB18030 and the character to be searched is a digit. */
857 # undef strrchr
858 /* Assume strrchr is always declared. */
859 _GL_WARN_ON_USE_CXX (strrchr,
860 const char *, char *, (const char *, int),
861 "strrchr cannot work correctly on character strings "
862 "in some multibyte locales - "
863 "use mbsrchr if you care about internationalization");
864 #endif
865
866 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
867 If one is found, overwrite it with a NUL, and advance *STRINGP
868 to point to the next char after it. Otherwise, set *STRINGP to NULL.
869 If *STRINGP was already NULL, nothing happens.
870 Return the old value of *STRINGP.
871
872 This is a variant of strtok() that is multithread-safe and supports
873 empty fields.
874
875 Caveat: It modifies the original string.
876 Caveat: These functions cannot be used on constant strings.
877 Caveat: The identity of the delimiting character is lost.
878 Caveat: It doesn't work with multibyte strings unless all of the delimiter
879 characters are ASCII characters < 0x30.
880
881 See also strtok_r(). */
882 #if @GNULIB_STRSEP@
883 # if ! @HAVE_STRSEP@
884 _GL_FUNCDECL_SYS (strsep, char *,
885 (char **restrict __stringp, char const *restrict __delim)
886 _GL_ARG_NONNULL ((1, 2)));
887 # endif
888 _GL_CXXALIAS_SYS (strsep, char *,
889 (char **restrict __stringp, char const *restrict __delim));
890 _GL_CXXALIASWARN (strsep);
891 # if defined GNULIB_POSIXCHECK
892 # undef strsep
893 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
894 "in multibyte locales - "
895 "use mbssep if you care about internationalization");
896 # endif
897 #elif defined GNULIB_POSIXCHECK
898 # undef strsep
899 # if HAVE_RAW_DECL_STRSEP
900 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
901 "use gnulib module strsep for portability");
902 # endif
903 #endif
904
905 #if @GNULIB_STRSTR@
906 # if @REPLACE_STRSTR@
907 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
908 # define strstr rpl_strstr
909 # endif
910 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
911 _GL_ATTRIBUTE_PURE
912 _GL_ARG_NONNULL ((1, 2)));
913 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
914 # else
915 /* On some systems, this function is defined as an overloaded function:
916 extern "C++" { const char * strstr (const char *, const char *); }
917 extern "C++" { char * strstr (char *, const char *); } */
918 _GL_CXXALIAS_SYS_CAST2 (strstr,
919 char *, (const char *haystack, const char *needle),
920 const char *, (const char *haystack, const char *needle));
921 # endif
922 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
923 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
924 || defined __clang__)
925 _GL_CXXALIASWARN1 (strstr, char *,
926 (char *haystack, const char *needle)
927 _GL_ATTRIBUTE_NOTHROW);
928 _GL_CXXALIASWARN1 (strstr, const char *,
929 (const char *haystack, const char *needle)
930 _GL_ATTRIBUTE_NOTHROW);
931 # elif __GLIBC__ >= 2
932 _GL_CXXALIASWARN (strstr);
933 # endif
934 #elif defined GNULIB_POSIXCHECK
935 /* strstr() does not work with multibyte strings if the locale encoding is
936 different from UTF-8:
937 POSIX says that it operates on "strings", and "string" in POSIX is defined
938 as a sequence of bytes, not of characters. */
939 # undef strstr
940 /* Assume strstr is always declared. */
941 _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
942 "work correctly on character strings in most "
943 "multibyte locales - "
944 "use mbsstr if you care about internationalization, "
945 "or use strstr if you care about speed");
946 #endif
947
948 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
949 comparison. */
950 #if @GNULIB_STRCASESTR@
951 # if @REPLACE_STRCASESTR@
952 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
953 # define strcasestr rpl_strcasestr
954 # endif
955 _GL_FUNCDECL_RPL (strcasestr, char *,
956 (const char *haystack, const char *needle)
957 _GL_ATTRIBUTE_PURE
958 _GL_ARG_NONNULL ((1, 2)));
959 _GL_CXXALIAS_RPL (strcasestr, char *,
960 (const char *haystack, const char *needle));
961 # else
962 # if ! @HAVE_STRCASESTR@
963 _GL_FUNCDECL_SYS (strcasestr, char *,
964 (const char *haystack, const char *needle)
965 _GL_ATTRIBUTE_PURE
966 _GL_ARG_NONNULL ((1, 2)));
967 # endif
968 /* On some systems, this function is defined as an overloaded function:
969 extern "C++" { const char * strcasestr (const char *, const char *); }
970 extern "C++" { char * strcasestr (char *, const char *); } */
971 _GL_CXXALIAS_SYS_CAST2 (strcasestr,
972 char *, (const char *haystack, const char *needle),
973 const char *, (const char *haystack, const char *needle));
974 # endif
975 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
976 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
977 || defined __clang__)
978 _GL_CXXALIASWARN1 (strcasestr, char *,
979 (char *haystack, const char *needle)
980 _GL_ATTRIBUTE_NOTHROW);
981 _GL_CXXALIASWARN1 (strcasestr, const char *,
982 (const char *haystack, const char *needle)
983 _GL_ATTRIBUTE_NOTHROW);
984 # elif __GLIBC__ >= 2
985 _GL_CXXALIASWARN (strcasestr);
986 # endif
987 #elif defined GNULIB_POSIXCHECK
988 /* strcasestr() does not work with multibyte strings:
989 It is a glibc extension, and glibc implements it only for unibyte
990 locales. */
991 # undef strcasestr
992 # if HAVE_RAW_DECL_STRCASESTR
993 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
994 "strings in multibyte locales - "
995 "use mbscasestr if you care about "
996 "internationalization, or use c-strcasestr if you want "
997 "a locale independent function");
998 # endif
999 #endif
1000
1001 /* Parse S into tokens separated by characters in DELIM.
1002 If S is NULL, the saved pointer in SAVE_PTR is used as
1003 the next starting point. For example:
1004 char s[] = "-abc-=-def";
1005 char *sp;
1006 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1007 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1008 x = strtok_r(NULL, "=", &sp); // x = NULL
1009 // s = "abc\0-def\0"
1010
1011 This is a variant of strtok() that is multithread-safe.
1012
1013 For the POSIX documentation for this function, see:
1014 https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html
1015
1016 Caveat: It modifies the original string.
1017 Caveat: These functions cannot be used on constant strings.
1018 Caveat: The identity of the delimiting character is lost.
1019 Caveat: It doesn't work with multibyte strings unless all of the delimiter
1020 characters are ASCII characters < 0x30.
1021
1022 See also strsep(). */
1023 #if @GNULIB_STRTOK_R@
1024 # if @REPLACE_STRTOK_R@
1025 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1026 # undef strtok_r
1027 # define strtok_r rpl_strtok_r
1028 # endif
1029 _GL_FUNCDECL_RPL (strtok_r, char *,
1030 (char *restrict s, char const *restrict delim,
1031 char **restrict save_ptr)
1032 _GL_ARG_NONNULL ((2, 3)));
1033 _GL_CXXALIAS_RPL (strtok_r, char *,
1034 (char *restrict s, char const *restrict delim,
1035 char **restrict save_ptr));
1036 # else
1037 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
1038 # undef strtok_r
1039 # endif
1040 # if ! @HAVE_DECL_STRTOK_R@
1041 _GL_FUNCDECL_SYS (strtok_r, char *,
1042 (char *restrict s, char const *restrict delim,
1043 char **restrict save_ptr)
1044 _GL_ARG_NONNULL ((2, 3)));
1045 # endif
1046 _GL_CXXALIAS_SYS (strtok_r, char *,
1047 (char *restrict s, char const *restrict delim,
1048 char **restrict save_ptr));
1049 # endif
1050 _GL_CXXALIASWARN (strtok_r);
1051 # if defined GNULIB_POSIXCHECK
1052 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
1053 "strings in multibyte locales - "
1054 "use mbstok_r if you care about internationalization");
1055 # endif
1056 #elif defined GNULIB_POSIXCHECK
1057 # undef strtok_r
1058 # if HAVE_RAW_DECL_STRTOK_R
1059 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
1060 "use gnulib module strtok_r for portability");
1061 # endif
1062 #endif
1063
1064
1065 /* The following functions are not specified by POSIX. They are gnulib
1066 extensions. */
1067
1068 #if @GNULIB_MBSLEN@
1069 /* Return the number of multibyte characters in the character string STRING.
1070 This considers multibyte characters, unlike strlen, which counts bytes. */
1071 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
1072 # undef mbslen
1073 # endif
1074 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
1075 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1076 # define mbslen rpl_mbslen
1077 # endif
1078 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string)
1079 _GL_ATTRIBUTE_PURE
1080 _GL_ARG_NONNULL ((1)));
1081 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
1082 # else
1083 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string)
1084 _GL_ATTRIBUTE_PURE
1085 _GL_ARG_NONNULL ((1)));
1086 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
1087 # endif
1088 # if __GLIBC__ >= 2
1089 _GL_CXXALIASWARN (mbslen);
1090 # endif
1091 #endif
1092
1093 #if @GNULIB_MBSNLEN@
1094 /* Return the number of multibyte characters in the character string starting
1095 at STRING and ending at STRING + LEN. */
1096 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
1097 _GL_ATTRIBUTE_PURE
1098 _GL_ARG_NONNULL ((1));
1099 #endif
1100
1101 #if @GNULIB_MBSCHR@
1102 /* Locate the first single-byte character C in the character string STRING,
1103 and return a pointer to it. Return NULL if C is not found in STRING.
1104 Unlike strchr(), this function works correctly in multibyte locales with
1105 encodings such as GB18030. */
1106 # if defined __hpux
1107 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1108 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
1109 # endif
1110 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
1111 _GL_ATTRIBUTE_PURE
1112 _GL_ARG_NONNULL ((1)));
1113 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
1114 # else
1115 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
1116 _GL_ATTRIBUTE_PURE
1117 _GL_ARG_NONNULL ((1)));
1118 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
1119 # endif
1120 _GL_CXXALIASWARN (mbschr);
1121 #endif
1122
1123 #if @GNULIB_MBSRCHR@
1124 /* Locate the last single-byte character C in the character string STRING,
1125 and return a pointer to it. Return NULL if C is not found in STRING.
1126 Unlike strrchr(), this function works correctly in multibyte locales with
1127 encodings such as GB18030. */
1128 # if defined __hpux || defined __INTERIX
1129 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1130 # define mbsrchr rpl_mbsrchr /* avoid collision with system function */
1131 # endif
1132 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
1133 _GL_ATTRIBUTE_PURE
1134 _GL_ARG_NONNULL ((1)));
1135 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
1136 # else
1137 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
1138 _GL_ATTRIBUTE_PURE
1139 _GL_ARG_NONNULL ((1)));
1140 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
1141 # endif
1142 _GL_CXXALIASWARN (mbsrchr);
1143 #endif
1144
1145 #if @GNULIB_MBSSTR@
1146 /* Find the first occurrence of the character string NEEDLE in the character
1147 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
1148 Unlike strstr(), this function works correctly in multibyte locales with
1149 encodings different from UTF-8. */
1150 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
1151 _GL_ATTRIBUTE_PURE
1152 _GL_ARG_NONNULL ((1, 2));
1153 #endif
1154
1155 #if @GNULIB_MBSCASECMP@
1156 /* Compare the character strings S1 and S2, ignoring case, returning less than,
1157 equal to or greater than zero if S1 is lexicographically less than, equal to
1158 or greater than S2.
1159 Note: This function may, in multibyte locales, return 0 for strings of
1160 different lengths!
1161 Unlike strcasecmp(), this function works correctly in multibyte locales. */
1162 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
1163 _GL_ATTRIBUTE_PURE
1164 _GL_ARG_NONNULL ((1, 2));
1165 #endif
1166
1167 #if @GNULIB_MBSNCASECMP@
1168 /* Compare the initial segment of the character string S1 consisting of at most
1169 N characters with the initial segment of the character string S2 consisting
1170 of at most N characters, ignoring case, returning less than, equal to or
1171 greater than zero if the initial segment of S1 is lexicographically less
1172 than, equal to or greater than the initial segment of S2.
1173 Note: This function may, in multibyte locales, return 0 for initial segments
1174 of different lengths!
1175 Unlike strncasecmp(), this function works correctly in multibyte locales.
1176 But beware that N is not a byte count but a character count! */
1177 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
1178 _GL_ATTRIBUTE_PURE
1179 _GL_ARG_NONNULL ((1, 2));
1180 #endif
1181
1182 #if @GNULIB_MBSPCASECMP@
1183 /* Compare the initial segment of the character string STRING consisting of
1184 at most mbslen (PREFIX) characters with the character string PREFIX,
1185 ignoring case. If the two match, return a pointer to the first byte
1186 after this prefix in STRING. Otherwise, return NULL.
1187 Note: This function may, in multibyte locales, return non-NULL if STRING
1188 is of smaller length than PREFIX!
1189 Unlike strncasecmp(), this function works correctly in multibyte
1190 locales. */
1191 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
1192 _GL_ATTRIBUTE_PURE
1193 _GL_ARG_NONNULL ((1, 2));
1194 #endif
1195
1196 #if @GNULIB_MBSCASESTR@
1197 /* Find the first occurrence of the character string NEEDLE in the character
1198 string HAYSTACK, using case-insensitive comparison.
1199 Note: This function may, in multibyte locales, return success even if
1200 strlen (haystack) < strlen (needle) !
1201 Unlike strcasestr(), this function works correctly in multibyte locales. */
1202 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
1203 _GL_ATTRIBUTE_PURE
1204 _GL_ARG_NONNULL ((1, 2));
1205 #endif
1206
1207 #if @GNULIB_MBSCSPN@
1208 /* Find the first occurrence in the character string STRING of any character
1209 in the character string ACCEPT. Return the number of bytes from the
1210 beginning of the string to this occurrence, or to the end of the string
1211 if none exists.
1212 Unlike strcspn(), this function works correctly in multibyte locales. */
1213 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
1214 _GL_ATTRIBUTE_PURE
1215 _GL_ARG_NONNULL ((1, 2));
1216 #endif
1217
1218 #if @GNULIB_MBSPBRK@
1219 /* Find the first occurrence in the character string STRING of any character
1220 in the character string ACCEPT. Return the pointer to it, or NULL if none
1221 exists.
1222 Unlike strpbrk(), this function works correctly in multibyte locales. */
1223 # if defined __hpux
1224 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1225 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1226 # endif
1227 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
1228 _GL_ATTRIBUTE_PURE
1229 _GL_ARG_NONNULL ((1, 2)));
1230 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
1231 # else
1232 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
1233 _GL_ATTRIBUTE_PURE
1234 _GL_ARG_NONNULL ((1, 2)));
1235 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
1236 # endif
1237 _GL_CXXALIASWARN (mbspbrk);
1238 #endif
1239
1240 #if @GNULIB_MBSSPN@
1241 /* Find the first occurrence in the character string STRING of any character
1242 not in the character string REJECT. Return the number of bytes from the
1243 beginning of the string to this occurrence, or to the end of the string
1244 if none exists.
1245 Unlike strspn(), this function works correctly in multibyte locales. */
1246 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
1247 _GL_ATTRIBUTE_PURE
1248 _GL_ARG_NONNULL ((1, 2));
1249 #endif
1250
1251 #if @GNULIB_MBSSEP@
1252 /* Search the next delimiter (multibyte character listed in the character
1253 string DELIM) starting at the character string *STRINGP.
1254 If one is found, overwrite it with a NUL, and advance *STRINGP to point
1255 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
1256 If *STRINGP was already NULL, nothing happens.
1257 Return the old value of *STRINGP.
1258
1259 This is a variant of mbstok_r() that supports empty fields.
1260
1261 Caveat: It modifies the original string.
1262 Caveat: These functions cannot be used on constant strings.
1263 Caveat: The identity of the delimiting character is lost.
1264
1265 See also mbstok_r(). */
1266 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
1267 _GL_ARG_NONNULL ((1, 2));
1268 #endif
1269
1270 #if @GNULIB_MBSTOK_R@
1271 /* Parse the character string STRING into tokens separated by characters in
1272 the character string DELIM.
1273 If STRING is NULL, the saved pointer in SAVE_PTR is used as
1274 the next starting point. For example:
1275 char s[] = "-abc-=-def";
1276 char *sp;
1277 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1278 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1279 x = mbstok_r(NULL, "=", &sp); // x = NULL
1280 // s = "abc\0-def\0"
1281
1282 Caveat: It modifies the original string.
1283 Caveat: These functions cannot be used on constant strings.
1284 Caveat: The identity of the delimiting character is lost.
1285
1286 See also mbssep(). */
1287 _GL_EXTERN_C char * mbstok_r (char *restrict string, const char *delim,
1288 char **save_ptr)
1289 _GL_ARG_NONNULL ((2, 3));
1290 #endif
1291
1292 /* Map any int, typically from errno, into an error message. */
1293 #if @GNULIB_STRERROR@
1294 # if @REPLACE_STRERROR@
1295 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1296 # undef strerror
1297 # define strerror rpl_strerror
1298 # endif
1299 _GL_FUNCDECL_RPL (strerror, char *, (int));
1300 _GL_CXXALIAS_RPL (strerror, char *, (int));
1301 # else
1302 _GL_CXXALIAS_SYS (strerror, char *, (int));
1303 # endif
1304 # if __GLIBC__ >= 2
1305 _GL_CXXALIASWARN (strerror);
1306 # endif
1307 #elif defined GNULIB_POSIXCHECK
1308 # undef strerror
1309 /* Assume strerror is always declared. */
1310 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
1311 "use gnulib module strerror to guarantee non-NULL result");
1312 #endif
1313
1314 /* Map any int, typically from errno, into an error message. Multithread-safe.
1315 Uses the POSIX declaration, not the glibc declaration. */
1316 #if @GNULIB_STRERROR_R@
1317 # if @REPLACE_STRERROR_R@
1318 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1319 # undef strerror_r
1320 # define strerror_r rpl_strerror_r
1321 # endif
1322 _GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)
1323 _GL_ARG_NONNULL ((2)));
1324 _GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
1325 # else
1326 # if !@HAVE_DECL_STRERROR_R@
1327 _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)
1328 _GL_ARG_NONNULL ((2)));
1329 # endif
1330 _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
1331 # endif
1332 # if __GLIBC__ >= 2 && @HAVE_DECL_STRERROR_R@
1333 _GL_CXXALIASWARN (strerror_r);
1334 # endif
1335 #elif defined GNULIB_POSIXCHECK
1336 # undef strerror_r
1337 # if HAVE_RAW_DECL_STRERROR_R
1338 _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
1339 "use gnulib module strerror_r-posix for portability");
1340 # endif
1341 #endif
1342
1343 /* Return the name of the system error code ERRNUM. */
1344 #if @GNULIB_STRERRORNAME_NP@
1345 # if @REPLACE_STRERRORNAME_NP@
1346 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1347 # undef strerrorname_np
1348 # define strerrorname_np rpl_strerrorname_np
1349 # endif
1350 _GL_FUNCDECL_RPL (strerrorname_np, const char *, (int errnum));
1351 _GL_CXXALIAS_RPL (strerrorname_np, const char *, (int errnum));
1352 # else
1353 # if !@HAVE_STRERRORNAME_NP@
1354 _GL_FUNCDECL_SYS (strerrorname_np, const char *, (int errnum));
1355 # endif
1356 _GL_CXXALIAS_SYS (strerrorname_np, const char *, (int errnum));
1357 # endif
1358 _GL_CXXALIASWARN (strerrorname_np);
1359 #elif defined GNULIB_POSIXCHECK
1360 # undef strerrorname_np
1361 # if HAVE_RAW_DECL_STRERRORNAME_NP
1362 _GL_WARN_ON_USE (strerrorname_np, "strerrorname_np is unportable - "
1363 "use gnulib module strerrorname_np for portability");
1364 # endif
1365 #endif
1366
1367 /* Return an abbreviation string for the signal number SIG. */
1368 #if @GNULIB_SIGABBREV_NP@
1369 # if ! @HAVE_SIGABBREV_NP@
1370 _GL_FUNCDECL_SYS (sigabbrev_np, const char *, (int sig));
1371 # endif
1372 _GL_CXXALIAS_SYS (sigabbrev_np, const char *, (int sig));
1373 _GL_CXXALIASWARN (sigabbrev_np);
1374 #elif defined GNULIB_POSIXCHECK
1375 # undef sigabbrev_np
1376 # if HAVE_RAW_DECL_SIGABBREV_NP
1377 _GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - "
1378 "use gnulib module sigabbrev_np for portability");
1379 # endif
1380 #endif
1381
1382 /* Return an English description string for the signal number SIG. */
1383 #if @GNULIB_SIGDESCR_NP@
1384 # if ! @HAVE_SIGDESCR_NP@
1385 _GL_FUNCDECL_SYS (sigdescr_np, const char *, (int sig));
1386 # endif
1387 _GL_CXXALIAS_SYS (sigdescr_np, const char *, (int sig));
1388 _GL_CXXALIASWARN (sigdescr_np);
1389 #elif defined GNULIB_POSIXCHECK
1390 # undef sigdescr_np
1391 # if HAVE_RAW_DECL_SIGDESCR_NP
1392 _GL_WARN_ON_USE (sigdescr_np, "sigdescr_np is unportable - "
1393 "use gnulib module sigdescr_np for portability");
1394 # endif
1395 #endif
1396
1397 #if @GNULIB_STRSIGNAL@
1398 # if @REPLACE_STRSIGNAL@
1399 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1400 # define strsignal rpl_strsignal
1401 # endif
1402 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
1403 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
1404 # else
1405 # if ! @HAVE_DECL_STRSIGNAL@
1406 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
1407 # endif
1408 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
1409 'const char *'. */
1410 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
1411 # endif
1412 _GL_CXXALIASWARN (strsignal);
1413 #elif defined GNULIB_POSIXCHECK
1414 # undef strsignal
1415 # if HAVE_RAW_DECL_STRSIGNAL
1416 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
1417 "use gnulib module strsignal for portability");
1418 # endif
1419 #endif
1420
1421 #if @GNULIB_STRVERSCMP@
1422 # if !@HAVE_STRVERSCMP@
1423 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
1424 _GL_ATTRIBUTE_PURE
1425 _GL_ARG_NONNULL ((1, 2)));
1426 # endif
1427 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
1428 _GL_CXXALIASWARN (strverscmp);
1429 #elif defined GNULIB_POSIXCHECK
1430 # undef strverscmp
1431 # if HAVE_RAW_DECL_STRVERSCMP
1432 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1433 "use gnulib module strverscmp for portability");
1434 # endif
1435 #endif
1436
1437
1438 #endif /* _@GUARD_PREFIX@_STRING_H */
1439 #endif /* _@GUARD_PREFIX@_STRING_H */
1440 #endif