Debian Codegraph @

lib/string.in.h

raw symbols SCIP
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 /* NetBSD 5.0 mis-defines NULL. */
48 #include <stddef.h>
49
50 /* MirBSD defines mbslen as a macro. */
51 #if @GNULIB_MBSLEN@ && defined __MirBSD__
52 # include <wchar.h>
53 #endif
54
55 /* NetBSD 5.0 declares strsignal in <unistd.h>, not in <string.h>. */
56 /* But in any case avoid namespace pollution on glibc systems. */
57 #if (@GNULIB_STRSIGNAL@ || defined GNULIB_POSIXCHECK) && defined __NetBSD__ \
58 && ! defined __GLIBC__
59 # include <unistd.h>
60 #endif
61
62 /* AIX 7.2 and Android 13 declare ffsl and ffsll in <strings.h>, not in
63 <string.h>. */
64 /* But in any case avoid namespace pollution on glibc systems. */
65 #if ((@GNULIB_FFSL@ || @GNULIB_FFSLL@ || defined GNULIB_POSIXCHECK) \
66 && (defined _AIX || defined __ANDROID__)) \
67 && ! defined __GLIBC__
68 # include <strings.h>
69 #endif
70
71 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
72 that can be freed by passing them as the Ith argument to the
73 function F. */
74 #ifndef _GL_ATTRIBUTE_DEALLOC
75 # if __GNUC__ >= 11
76 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
77 # else
78 # define _GL_ATTRIBUTE_DEALLOC(f, i)
79 # endif
80 #endif
81
82 /* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
83 can be freed via 'free'; it can be used only after declaring 'free'. */
84 /* Applies to: functions. Cannot be used on inline functions. */
85 #ifndef _GL_ATTRIBUTE_DEALLOC_FREE
86 # if defined __cplusplus && defined __GNUC__ && !defined __clang__
87 /* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
88 # define _GL_ATTRIBUTE_DEALLOC_FREE \
89 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
90 # else
91 # define _GL_ATTRIBUTE_DEALLOC_FREE \
92 _GL_ATTRIBUTE_DEALLOC (free, 1)
93 # endif
94 #endif
95
96 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
97 allocated memory. */
98 /* Applies to: functions. */
99 #ifndef _GL_ATTRIBUTE_MALLOC
100 # if __GNUC__ >= 3 || defined __clang__
101 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
102 # else
103 # define _GL_ATTRIBUTE_MALLOC
104 # endif
105 #endif
106
107 /* The __attribute__ feature is available in gcc versions 2.5 and later.
108 The attribute __pure__ was added in gcc 2.96. */
109 #ifndef _GL_ATTRIBUTE_PURE
110 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
111 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
112 # else
113 # define _GL_ATTRIBUTE_PURE /* empty */
114 # endif
115 #endif
116
117 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
118
119 /* The definition of _GL_ARG_NONNULL is copied here. */
120
121 /* The definition of _GL_WARN_ON_USE is copied here. */
122
123 /* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though <stdlib.h> may not have
124 been included yet. */
125 #if @GNULIB_FREE_POSIX@
126 # if (@REPLACE_FREE@ && !defined free \
127 && !(defined __cplusplus && defined GNULIB_NAMESPACE))
128 /* We can't do '#define free rpl_free' here. */
129 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
130 _GL_EXTERN_C void rpl_free (void *) throw ();
131 # else
132 _GL_EXTERN_C void rpl_free (void *);
133 # endif
134 # undef _GL_ATTRIBUTE_DEALLOC_FREE
135 # define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
136 # else
137 # if defined _MSC_VER && !defined free
138 _GL_EXTERN_C
139 # if defined _DLL
140 __declspec (dllimport)
141 # endif
142 void __cdecl free (void *);
143 # else
144 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
145 _GL_EXTERN_C void free (void *) throw ();
146 # else
147 _GL_EXTERN_C void free (void *);
148 # endif
149 # endif
150 # endif
151 #else
152 # if defined _MSC_VER && !defined free
153 _GL_EXTERN_C
154 # if defined _DLL
155 __declspec (dllimport)
156 # endif
157 void __cdecl free (void *);
158 # else
159 # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
160 _GL_EXTERN_C void free (void *) throw ();
161 # else
162 _GL_EXTERN_C void free (void *);
163 # endif
164 # endif
165 #endif
166
167 /* Clear a block of memory. The compiler will not delete a call to
168 this function, even if the block is dead after the call. */
169 #if @GNULIB_EXPLICIT_BZERO@
170 # if ! @HAVE_EXPLICIT_BZERO@
171 _GL_FUNCDECL_SYS (explicit_bzero, void,
172 (void *__dest, size_t __n) _GL_ARG_NONNULL ((1)));
173 # endif
174 _GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n));
175 _GL_CXXALIASWARN (explicit_bzero);
176 #elif defined GNULIB_POSIXCHECK
177 # undef explicit_bzero
178 # if HAVE_RAW_DECL_EXPLICIT_BZERO
179 _GL_WARN_ON_USE (explicit_bzero, "explicit_bzero is unportable - "
180 "use gnulib module explicit_bzero for portability");
181 # endif
182 #endif
183
184 /* Find the index of the least-significant set bit. */
185 #if @GNULIB_FFSL@
186 # if !@HAVE_FFSL@
187 _GL_FUNCDECL_SYS (ffsl, int, (long int i));
188 # endif
189 _GL_CXXALIAS_SYS (ffsl, int, (long int i));
190 _GL_CXXALIASWARN (ffsl);
191 #elif defined GNULIB_POSIXCHECK
192 # undef ffsl
193 # if HAVE_RAW_DECL_FFSL
194 _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
195 # endif
196 #endif
197
198
199 /* Find the index of the least-significant set bit. */
200 #if @GNULIB_FFSLL@
201 # if @REPLACE_FFSLL@
202 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
203 # define ffsll rpl_ffsll
204 # endif
205 _GL_FUNCDECL_RPL (ffsll, int, (long long int i));
206 _GL_CXXALIAS_RPL (ffsll, int, (long long int i));
207 # else
208 # if !@HAVE_FFSLL@
209 _GL_FUNCDECL_SYS (ffsll, int, (long long int i));
210 # endif
211 _GL_CXXALIAS_SYS (ffsll, int, (long long int i));
212 # endif
213 _GL_CXXALIASWARN (ffsll);
214 #elif defined GNULIB_POSIXCHECK
215 # undef ffsll
216 # if HAVE_RAW_DECL_FFSLL
217 _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
218 # endif
219 #endif
220
221
222 #if @GNULIB_MDA_MEMCCPY@
223 /* On native Windows, map 'memccpy' to '_memccpy', so that -loldnames is not
224 required. In C++ with GNULIB_NAMESPACE, avoid differences between
225 platforms by defining GNULIB_NAMESPACE::memccpy always. */
226 # if defined _WIN32 && !defined __CYGWIN__
227 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
228 # undef memccpy
229 # define memccpy _memccpy
230 # endif
231 _GL_CXXALIAS_MDA (memccpy, void *,
232 (void *dest, const void *src, int c, size_t n));
233 # else
234 _GL_CXXALIAS_SYS (memccpy, void *,
235 (void *dest, const void *src, int c, size_t n));
236 # endif
237 _GL_CXXALIASWARN (memccpy);
238 #endif
239
240
241 /* Return the first instance of C within N bytes of S, or NULL. */
242 #if @GNULIB_MEMCHR@
243 # if @REPLACE_MEMCHR@
244 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
245 # undef memchr
246 # define memchr rpl_memchr
247 # endif
248 _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
249 _GL_ATTRIBUTE_PURE
250 _GL_ARG_NONNULL ((1)));
251 _GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
252 # else
253 /* On some systems, this function is defined as an overloaded function:
254 extern "C" { const void * std::memchr (const void *, int, size_t); }
255 extern "C++" { void * std::memchr (void *, int, size_t); } */
256 _GL_CXXALIAS_SYS_CAST2 (memchr,
257 void *, (void const *__s, int __c, size_t __n),
258 void const *, (void const *__s, int __c, size_t __n));
259 # endif
260 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
261 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
262 || defined __clang__)
263 _GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n) throw ());
264 _GL_CXXALIASWARN1 (memchr, void const *,
265 (void const *__s, int __c, size_t __n) throw ());
266 # elif __GLIBC__ >= 2
267 _GL_CXXALIASWARN (memchr);
268 # endif
269 #elif defined GNULIB_POSIXCHECK
270 # undef memchr
271 /* Assume memchr is always declared. */
272 _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
273 "use gnulib module memchr for portability" );
274 #endif
275
276 /* Return the first occurrence of NEEDLE in HAYSTACK. */
277 #if @GNULIB_MEMMEM@
278 # if @REPLACE_MEMMEM@
279 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
280 # define memmem rpl_memmem
281 # endif
282 _GL_FUNCDECL_RPL (memmem, void *,
283 (void const *__haystack, size_t __haystack_len,
284 void const *__needle, size_t __needle_len)
285 _GL_ATTRIBUTE_PURE
286 _GL_ARG_NONNULL ((1, 3)));
287 _GL_CXXALIAS_RPL (memmem, void *,
288 (void const *__haystack, size_t __haystack_len,
289 void const *__needle, size_t __needle_len));
290 # else
291 # if ! @HAVE_DECL_MEMMEM@
292 _GL_FUNCDECL_SYS (memmem, void *,
293 (void const *__haystack, size_t __haystack_len,
294 void const *__needle, size_t __needle_len)
295 _GL_ATTRIBUTE_PURE
296 _GL_ARG_NONNULL ((1, 3)));
297 # endif
298 _GL_CXXALIAS_SYS (memmem, void *,
299 (void const *__haystack, size_t __haystack_len,
300 void const *__needle, size_t __needle_len));
301 # endif
302 _GL_CXXALIASWARN (memmem);
303 #elif defined GNULIB_POSIXCHECK
304 # undef memmem
305 # if HAVE_RAW_DECL_MEMMEM
306 _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
307 "use gnulib module memmem-simple for portability, "
308 "and module memmem for speed" );
309 # endif
310 #endif
311
312 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
313 last written byte. */
314 #if @GNULIB_MEMPCPY@
315 # if @REPLACE_MEMPCPY@
316 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
317 # undef mempcpy
318 # define mempcpy rpl_mempcpy
319 # endif
320 _GL_FUNCDECL_RPL (mempcpy, void *,
321 (void *restrict __dest, void const *restrict __src,
322 size_t __n)
323 _GL_ARG_NONNULL ((1, 2)));
324 _GL_CXXALIAS_RPL (mempcpy, void *,
325 (void *restrict __dest, void const *restrict __src,
326 size_t __n));
327 # else
328 # if !@HAVE_MEMPCPY@
329 _GL_FUNCDECL_SYS (mempcpy, void *,
330 (void *restrict __dest, void const *restrict __src,
331 size_t __n)
332 _GL_ARG_NONNULL ((1, 2)));
333 # endif
334 _GL_CXXALIAS_SYS (mempcpy, void *,
335 (void *restrict __dest, void const *restrict __src,
336 size_t __n));
337 # endif
338 # if __GLIBC__ >= 2
339 _GL_CXXALIASWARN (mempcpy);
340 # endif
341 #elif defined GNULIB_POSIXCHECK
342 # undef mempcpy
343 # if HAVE_RAW_DECL_MEMPCPY
344 _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
345 "use gnulib module mempcpy for portability");
346 # endif
347 #endif
348
349 /* Search backwards through a block for a byte (specified as an int). */
350 #if @GNULIB_MEMRCHR@
351 # if ! @HAVE_DECL_MEMRCHR@
352 _GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
353 _GL_ATTRIBUTE_PURE
354 _GL_ARG_NONNULL ((1)));
355 # endif
356 /* On some systems, this function is defined as an overloaded function:
357 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
358 extern "C++" { void * std::memrchr (void *, int, size_t); } */
359 _GL_CXXALIAS_SYS_CAST2 (memrchr,
360 void *, (void const *, int, size_t),
361 void const *, (void const *, int, size_t));
362 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
363 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
364 || defined __clang__)
365 _GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t) throw ());
366 _GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t) throw ());
367 # elif __GLIBC__ >= 2
368 _GL_CXXALIASWARN (memrchr);
369 # endif
370 #elif defined GNULIB_POSIXCHECK
371 # undef memrchr
372 # if HAVE_RAW_DECL_MEMRCHR
373 _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
374 "use gnulib module memrchr for portability");
375 # endif
376 #endif
377
378 /* Overwrite a block of memory. The compiler will not optimize
379 effects away, even if the block is dead after the call. */
380 #if @GNULIB_MEMSET_EXPLICIT@
381 # if ! @HAVE_MEMSET_EXPLICIT@
382 _GL_FUNCDECL_SYS (memset_explicit, void *,
383 (void *__dest, int __c, size_t __n) _GL_ARG_NONNULL ((1)));
384 # endif
385 _GL_CXXALIAS_SYS (memset_explicit, void *, (void *__dest, int __c, size_t __n));
386 _GL_CXXALIASWARN (memset_explicit);
387 #elif defined GNULIB_POSIXCHECK
388 # undef memset_explicit
389 # if HAVE_RAW_DECL_MEMSET_EXPLICIT
390 _GL_WARN_ON_USE (memset_explicit, "memset_explicit is unportable - "
391 "use gnulib module memset_explicit for portability");
392 # endif
393 #endif
394
395 /* Find the first occurrence of C in S. More efficient than
396 memchr(S,C,N), at the expense of undefined behavior if C does not
397 occur within N bytes. */
398 #if @GNULIB_RAWMEMCHR@
399 # if ! @HAVE_RAWMEMCHR@
400 _GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
401 _GL_ATTRIBUTE_PURE
402 _GL_ARG_NONNULL ((1)));
403 # endif
404 /* On some systems, this function is defined as an overloaded function:
405 extern "C++" { const void * std::rawmemchr (const void *, int); }
406 extern "C++" { void * std::rawmemchr (void *, int); } */
407 _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
408 void *, (void const *__s, int __c_in),
409 void const *, (void const *__s, int __c_in));
410 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
411 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
412 || defined __clang__)
413 _GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in) throw ());
414 _GL_CXXALIASWARN1 (rawmemchr, void const *,
415 (void const *__s, int __c_in) throw ());
416 # else
417 _GL_CXXALIASWARN (rawmemchr);
418 # endif
419 #elif defined GNULIB_POSIXCHECK
420 # undef rawmemchr
421 # if HAVE_RAW_DECL_RAWMEMCHR
422 _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
423 "use gnulib module rawmemchr for portability");
424 # endif
425 #endif
426
427 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
428 #if @GNULIB_STPCPY@
429 # if @REPLACE_STPCPY@
430 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
431 # undef stpcpy
432 # define stpcpy rpl_stpcpy
433 # endif
434 _GL_FUNCDECL_RPL (stpcpy, char *,
435 (char *restrict __dst, char const *restrict __src)
436 _GL_ARG_NONNULL ((1, 2)));
437 _GL_CXXALIAS_RPL (stpcpy, char *,
438 (char *restrict __dst, char const *restrict __src));
439 # else
440 # if !@HAVE_STPCPY@
441 _GL_FUNCDECL_SYS (stpcpy, char *,
442 (char *restrict __dst, char const *restrict __src)
443 _GL_ARG_NONNULL ((1, 2)));
444 # endif
445 _GL_CXXALIAS_SYS (stpcpy, char *,
446 (char *restrict __dst, char const *restrict __src));
447 # endif
448 # if __GLIBC__ >= 2
449 _GL_CXXALIASWARN (stpcpy);
450 # endif
451 #elif defined GNULIB_POSIXCHECK
452 # undef stpcpy
453 # if HAVE_RAW_DECL_STPCPY
454 _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
455 "use gnulib module stpcpy for portability");
456 # endif
457 #endif
458
459 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
460 last non-NUL byte written into DST. */
461 #if @GNULIB_STPNCPY@
462 # if @REPLACE_STPNCPY@
463 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
464 # undef stpncpy
465 # define stpncpy rpl_stpncpy
466 # endif
467 _GL_FUNCDECL_RPL (stpncpy, char *,
468 (char *restrict __dst, char const *restrict __src,
469 size_t __n)
470 _GL_ARG_NONNULL ((1, 2)));
471 _GL_CXXALIAS_RPL (stpncpy, char *,
472 (char *restrict __dst, char const *restrict __src,
473 size_t __n));
474 # else
475 # if ! @HAVE_STPNCPY@
476 _GL_FUNCDECL_SYS (stpncpy, char *,
477 (char *restrict __dst, char const *restrict __src,
478 size_t __n)
479 _GL_ARG_NONNULL ((1, 2)));
480 # endif
481 _GL_CXXALIAS_SYS (stpncpy, char *,
482 (char *restrict __dst, char const *restrict __src,
483 size_t __n));
484 # endif
485 # if __GLIBC__ >= 2
486 _GL_CXXALIASWARN (stpncpy);
487 # endif
488 #elif defined GNULIB_POSIXCHECK
489 # undef stpncpy
490 # if HAVE_RAW_DECL_STPNCPY
491 _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
492 "use gnulib module stpncpy for portability");
493 # endif
494 #endif
495
496 #if defined GNULIB_POSIXCHECK
497 /* strchr() does not work with multibyte strings if the locale encoding is
498 GB18030 and the character to be searched is a digit. */
499 # undef strchr
500 /* Assume strchr is always declared. */
501 _GL_WARN_ON_USE_CXX (strchr,
502 const char *, char *, (const char *, int),
503 "strchr cannot work correctly on character strings "
504 "in some multibyte locales - "
505 "use mbschr if you care about internationalization");
506 #endif
507
508 /* Find the first occurrence of C in S or the final NUL byte. */
509 #if @GNULIB_STRCHRNUL@
510 # if @REPLACE_STRCHRNUL@
511 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
512 # define strchrnul rpl_strchrnul
513 # endif
514 _GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in)
515 _GL_ATTRIBUTE_PURE
516 _GL_ARG_NONNULL ((1)));
517 _GL_CXXALIAS_RPL (strchrnul, char *,
518 (const char *str, int ch));
519 # else
520 # if ! @HAVE_STRCHRNUL@
521 _GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
522 _GL_ATTRIBUTE_PURE
523 _GL_ARG_NONNULL ((1)));
524 # endif
525 /* On some systems, this function is defined as an overloaded function:
526 extern "C++" { const char * std::strchrnul (const char *, int); }
527 extern "C++" { char * std::strchrnul (char *, int); } */
528 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
529 char *, (char const *__s, int __c_in),
530 char const *, (char const *__s, int __c_in));
531 # endif
532 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
533 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
534 || defined __clang__)
535 _GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in) throw ());
536 _GL_CXXALIASWARN1 (strchrnul, char const *,
537 (char const *__s, int __c_in) throw ());
538 # elif __GLIBC__ >= 2
539 _GL_CXXALIASWARN (strchrnul);
540 # endif
541 #elif defined GNULIB_POSIXCHECK
542 # undef strchrnul
543 # if HAVE_RAW_DECL_STRCHRNUL
544 _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
545 "use gnulib module strchrnul for portability");
546 # endif
547 #endif
548
549 /* Duplicate S, returning an identical malloc'd string. */
550 #if @GNULIB_STRDUP@
551 # if @REPLACE_STRDUP@
552 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
553 # undef strdup
554 # define strdup rpl_strdup
555 # endif
556 _GL_FUNCDECL_RPL (strdup, char *,
557 (char const *__s)
558 _GL_ARG_NONNULL ((1))
559 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
560 _GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
561 # elif defined _WIN32 && !defined __CYGWIN__
562 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
563 # undef strdup
564 # define strdup _strdup
565 # endif
566 _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
567 # else
568 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
569 /* strdup exists as a function and as a macro. Get rid of the macro. */
570 # undef strdup
571 # endif
572 # if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup
573 _GL_FUNCDECL_SYS (strdup, char *,
574 (char const *__s)
575 _GL_ARG_NONNULL ((1))
576 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
577 # endif
578 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
579 # endif
580 _GL_CXXALIASWARN (strdup);
581 #else
582 # if __GNUC__ >= 11 && !defined strdup
583 /* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */
584 _GL_FUNCDECL_SYS (strdup, char *,
585 (char const *__s)
586 _GL_ARG_NONNULL ((1))
587 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
588 # endif
589 # if defined GNULIB_POSIXCHECK
590 # undef strdup
591 # if HAVE_RAW_DECL_STRDUP
592 _GL_WARN_ON_USE (strdup, "strdup is unportable - "
593 "use gnulib module strdup for portability");
594 # endif
595 # elif @GNULIB_MDA_STRDUP@
596 /* On native Windows, map 'creat' to '_creat', so that -loldnames is not
597 required. In C++ with GNULIB_NAMESPACE, avoid differences between
598 platforms by defining GNULIB_NAMESPACE::strdup always. */
599 # if defined _WIN32 && !defined __CYGWIN__
600 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
601 # undef strdup
602 # define strdup _strdup
603 # endif
604 _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
605 # else
606 # if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
607 # undef strdup
608 # endif
609 _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
610 # endif
611 _GL_CXXALIASWARN (strdup);
612 # endif
613 #endif
614
615 /* Append no more than N characters from SRC onto DEST. */
616 #if @GNULIB_STRNCAT@
617 # if @REPLACE_STRNCAT@
618 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
619 # undef strncat
620 # define strncat rpl_strncat
621 # endif
622 _GL_FUNCDECL_RPL (strncat, char *,
623 (char *restrict dest, const char *restrict src, size_t n)
624 _GL_ARG_NONNULL ((1, 2)));
625 _GL_CXXALIAS_RPL (strncat, char *,
626 (char *restrict dest, const char *restrict src, size_t n));
627 # else
628 _GL_CXXALIAS_SYS (strncat, char *,
629 (char *restrict dest, const char *restrict src, size_t n));
630 # endif
631 # if __GLIBC__ >= 2
632 _GL_CXXALIASWARN (strncat);
633 # endif
634 #elif defined GNULIB_POSIXCHECK
635 # undef strncat
636 # if HAVE_RAW_DECL_STRNCAT
637 _GL_WARN_ON_USE (strncat, "strncat is unportable - "
638 "use gnulib module strncat for portability");
639 # endif
640 #endif
641
642 /* Return a newly allocated copy of at most N bytes of STRING. */
643 #if @GNULIB_STRNDUP@
644 # if @REPLACE_STRNDUP@
645 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
646 # undef strndup
647 # define strndup rpl_strndup
648 # endif
649 _GL_FUNCDECL_RPL (strndup, char *,
650 (char const *__s, size_t __n)
651 _GL_ARG_NONNULL ((1))
652 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
653 _GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n));
654 # else
655 # if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined strndup)
656 _GL_FUNCDECL_SYS (strndup, char *,
657 (char const *__s, size_t __n)
658 _GL_ARG_NONNULL ((1))
659 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
660 # endif
661 _GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n));
662 # endif
663 _GL_CXXALIASWARN (strndup);
664 #else
665 # if __GNUC__ >= 11 && !defined strndup
666 /* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */
667 _GL_FUNCDECL_SYS (strndup, char *,
668 (char const *__s, size_t __n)
669 _GL_ARG_NONNULL ((1))
670 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
671 # endif
672 # if defined GNULIB_POSIXCHECK
673 # undef strndup
674 # if HAVE_RAW_DECL_STRNDUP
675 _GL_WARN_ON_USE (strndup, "strndup is unportable - "
676 "use gnulib module strndup for portability");
677 # endif
678 # endif
679 #endif
680
681 /* Find the length (number of bytes) of STRING, but scan at most
682 MAXLEN bytes. If no '\0' terminator is found in that many bytes,
683 return MAXLEN. */
684 #if @GNULIB_STRNLEN@
685 # if @REPLACE_STRNLEN@
686 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
687 # undef strnlen
688 # define strnlen rpl_strnlen
689 # endif
690 _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen)
691 _GL_ATTRIBUTE_PURE
692 _GL_ARG_NONNULL ((1)));
693 _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen));
694 # else
695 # if ! @HAVE_DECL_STRNLEN@
696 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen)
697 _GL_ATTRIBUTE_PURE
698 _GL_ARG_NONNULL ((1)));
699 # endif
700 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__s, size_t __maxlen));
701 # endif
702 _GL_CXXALIASWARN (strnlen);
703 #elif defined GNULIB_POSIXCHECK
704 # undef strnlen
705 # if HAVE_RAW_DECL_STRNLEN
706 _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
707 "use gnulib module strnlen for portability");
708 # endif
709 #endif
710
711 #if defined GNULIB_POSIXCHECK
712 /* strcspn() assumes the second argument is a list of single-byte characters.
713 Even in this simple case, it does not work with multibyte strings if the
714 locale encoding is GB18030 and one of the characters to be searched is a
715 digit. */
716 # undef strcspn
717 /* Assume strcspn is always declared. */
718 _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
719 "in multibyte locales - "
720 "use mbscspn if you care about internationalization");
721 #endif
722
723 /* Find the first occurrence in S of any character in ACCEPT. */
724 #if @GNULIB_STRPBRK@
725 # if ! @HAVE_STRPBRK@
726 _GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
727 _GL_ATTRIBUTE_PURE
728 _GL_ARG_NONNULL ((1, 2)));
729 # endif
730 /* On some systems, this function is defined as an overloaded function:
731 extern "C" { const char * strpbrk (const char *, const char *); }
732 extern "C++" { char * strpbrk (char *, const char *); } */
733 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
734 char *, (char const *__s, char const *__accept),
735 const char *, (char const *__s, char const *__accept));
736 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
737 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
738 || defined __clang__)
739 _GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept) throw ());
740 _GL_CXXALIASWARN1 (strpbrk, char const *,
741 (char const *__s, char const *__accept) throw ());
742 # elif __GLIBC__ >= 2
743 _GL_CXXALIASWARN (strpbrk);
744 # endif
745 # if defined GNULIB_POSIXCHECK
746 /* strpbrk() assumes the second argument is a list of single-byte characters.
747 Even in this simple case, it does not work with multibyte strings if the
748 locale encoding is GB18030 and one of the characters to be searched is a
749 digit. */
750 # undef strpbrk
751 _GL_WARN_ON_USE_CXX (strpbrk,
752 const char *, char *, (const char *, const char *),
753 "strpbrk cannot work correctly on character strings "
754 "in multibyte locales - "
755 "use mbspbrk if you care about internationalization");
756 # endif
757 #elif defined GNULIB_POSIXCHECK
758 # undef strpbrk
759 # if HAVE_RAW_DECL_STRPBRK
760 _GL_WARN_ON_USE_CXX (strpbrk,
761 const char *, char *, (const char *, const char *),
762 "strpbrk is unportable - "
763 "use gnulib module strpbrk for portability");
764 # endif
765 #endif
766
767 #if defined GNULIB_POSIXCHECK
768 /* strspn() assumes the second argument is a list of single-byte characters.
769 Even in this simple case, it cannot work with multibyte strings. */
770 # undef strspn
771 /* Assume strspn is always declared. */
772 _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
773 "in multibyte locales - "
774 "use mbsspn if you care about internationalization");
775 #endif
776
777 #if defined GNULIB_POSIXCHECK
778 /* strrchr() does not work with multibyte strings if the locale encoding is
779 GB18030 and the character to be searched is a digit. */
780 # undef strrchr
781 /* Assume strrchr is always declared. */
782 _GL_WARN_ON_USE_CXX (strrchr,
783 const char *, char *, (const char *, int),
784 "strrchr cannot work correctly on character strings "
785 "in some multibyte locales - "
786 "use mbsrchr if you care about internationalization");
787 #endif
788
789 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
790 If one is found, overwrite it with a NUL, and advance *STRINGP
791 to point to the next char after it. Otherwise, set *STRINGP to NULL.
792 If *STRINGP was already NULL, nothing happens.
793 Return the old value of *STRINGP.
794
795 This is a variant of strtok() that is multithread-safe and supports
796 empty fields.
797
798 Caveat: It modifies the original string.
799 Caveat: These functions cannot be used on constant strings.
800 Caveat: The identity of the delimiting character is lost.
801 Caveat: It doesn't work with multibyte strings unless all of the delimiter
802 characters are ASCII characters < 0x30.
803
804 See also strtok_r(). */
805 #if @GNULIB_STRSEP@
806 # if ! @HAVE_STRSEP@
807 _GL_FUNCDECL_SYS (strsep, char *,
808 (char **restrict __stringp, char const *restrict __delim)
809 _GL_ARG_NONNULL ((1, 2)));
810 # endif
811 _GL_CXXALIAS_SYS (strsep, char *,
812 (char **restrict __stringp, char const *restrict __delim));
813 _GL_CXXALIASWARN (strsep);
814 # if defined GNULIB_POSIXCHECK
815 # undef strsep
816 _GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
817 "in multibyte locales - "
818 "use mbssep if you care about internationalization");
819 # endif
820 #elif defined GNULIB_POSIXCHECK
821 # undef strsep
822 # if HAVE_RAW_DECL_STRSEP
823 _GL_WARN_ON_USE (strsep, "strsep is unportable - "
824 "use gnulib module strsep for portability");
825 # endif
826 #endif
827
828 #if @GNULIB_STRSTR@
829 # if @REPLACE_STRSTR@
830 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
831 # define strstr rpl_strstr
832 # endif
833 _GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle)
834 _GL_ATTRIBUTE_PURE
835 _GL_ARG_NONNULL ((1, 2)));
836 _GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
837 # else
838 /* On some systems, this function is defined as an overloaded function:
839 extern "C++" { const char * strstr (const char *, const char *); }
840 extern "C++" { char * strstr (char *, const char *); } */
841 _GL_CXXALIAS_SYS_CAST2 (strstr,
842 char *, (const char *haystack, const char *needle),
843 const char *, (const char *haystack, const char *needle));
844 # endif
845 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
846 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
847 || defined __clang__)
848 _GL_CXXALIASWARN1 (strstr, char *,
849 (char *haystack, const char *needle) throw ());
850 _GL_CXXALIASWARN1 (strstr, const char *,
851 (const char *haystack, const char *needle) throw ());
852 # elif __GLIBC__ >= 2
853 _GL_CXXALIASWARN (strstr);
854 # endif
855 #elif defined GNULIB_POSIXCHECK
856 /* strstr() does not work with multibyte strings if the locale encoding is
857 different from UTF-8:
858 POSIX says that it operates on "strings", and "string" in POSIX is defined
859 as a sequence of bytes, not of characters. */
860 # undef strstr
861 /* Assume strstr is always declared. */
862 _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
863 "work correctly on character strings in most "
864 "multibyte locales - "
865 "use mbsstr if you care about internationalization, "
866 "or use strstr if you care about speed");
867 #endif
868
869 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
870 comparison. */
871 #if @GNULIB_STRCASESTR@
872 # if @REPLACE_STRCASESTR@
873 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
874 # define strcasestr rpl_strcasestr
875 # endif
876 _GL_FUNCDECL_RPL (strcasestr, char *,
877 (const char *haystack, const char *needle)
878 _GL_ATTRIBUTE_PURE
879 _GL_ARG_NONNULL ((1, 2)));
880 _GL_CXXALIAS_RPL (strcasestr, char *,
881 (const char *haystack, const char *needle));
882 # else
883 # if ! @HAVE_STRCASESTR@
884 _GL_FUNCDECL_SYS (strcasestr, char *,
885 (const char *haystack, const char *needle)
886 _GL_ATTRIBUTE_PURE
887 _GL_ARG_NONNULL ((1, 2)));
888 # endif
889 /* On some systems, this function is defined as an overloaded function:
890 extern "C++" { const char * strcasestr (const char *, const char *); }
891 extern "C++" { char * strcasestr (char *, const char *); } */
892 _GL_CXXALIAS_SYS_CAST2 (strcasestr,
893 char *, (const char *haystack, const char *needle),
894 const char *, (const char *haystack, const char *needle));
895 # endif
896 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
897 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
898 || defined __clang__)
899 _GL_CXXALIASWARN1 (strcasestr, char *,
900 (char *haystack, const char *needle) throw ());
901 _GL_CXXALIASWARN1 (strcasestr, const char *,
902 (const char *haystack, const char *needle) throw ());
903 # elif __GLIBC__ >= 2
904 _GL_CXXALIASWARN (strcasestr);
905 # endif
906 #elif defined GNULIB_POSIXCHECK
907 /* strcasestr() does not work with multibyte strings:
908 It is a glibc extension, and glibc implements it only for unibyte
909 locales. */
910 # undef strcasestr
911 # if HAVE_RAW_DECL_STRCASESTR
912 _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
913 "strings in multibyte locales - "
914 "use mbscasestr if you care about "
915 "internationalization, or use c-strcasestr if you want "
916 "a locale independent function");
917 # endif
918 #endif
919
920 /* Parse S into tokens separated by characters in DELIM.
921 If S is NULL, the saved pointer in SAVE_PTR is used as
922 the next starting point. For example:
923 char s[] = "-abc-=-def";
924 char *sp;
925 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
926 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
927 x = strtok_r(NULL, "=", &sp); // x = NULL
928 // s = "abc\0-def\0"
929
930 This is a variant of strtok() that is multithread-safe.
931
932 For the POSIX documentation for this function, see:
933 https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html
934
935 Caveat: It modifies the original string.
936 Caveat: These functions cannot be used on constant strings.
937 Caveat: The identity of the delimiting character is lost.
938 Caveat: It doesn't work with multibyte strings unless all of the delimiter
939 characters are ASCII characters < 0x30.
940
941 See also strsep(). */
942 #if @GNULIB_STRTOK_R@
943 # if @REPLACE_STRTOK_R@
944 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
945 # undef strtok_r
946 # define strtok_r rpl_strtok_r
947 # endif
948 _GL_FUNCDECL_RPL (strtok_r, char *,
949 (char *restrict s, char const *restrict delim,
950 char **restrict save_ptr)
951 _GL_ARG_NONNULL ((2, 3)));
952 _GL_CXXALIAS_RPL (strtok_r, char *,
953 (char *restrict s, char const *restrict delim,
954 char **restrict save_ptr));
955 # else
956 # if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK
957 # undef strtok_r
958 # endif
959 # if ! @HAVE_DECL_STRTOK_R@
960 _GL_FUNCDECL_SYS (strtok_r, char *,
961 (char *restrict s, char const *restrict delim,
962 char **restrict save_ptr)
963 _GL_ARG_NONNULL ((2, 3)));
964 # endif
965 _GL_CXXALIAS_SYS (strtok_r, char *,
966 (char *restrict s, char const *restrict delim,
967 char **restrict save_ptr));
968 # endif
969 _GL_CXXALIASWARN (strtok_r);
970 # if defined GNULIB_POSIXCHECK
971 _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
972 "strings in multibyte locales - "
973 "use mbstok_r if you care about internationalization");
974 # endif
975 #elif defined GNULIB_POSIXCHECK
976 # undef strtok_r
977 # if HAVE_RAW_DECL_STRTOK_R
978 _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
979 "use gnulib module strtok_r for portability");
980 # endif
981 #endif
982
983
984 /* The following functions are not specified by POSIX. They are gnulib
985 extensions. */
986
987 #if @GNULIB_MBSLEN@
988 /* Return the number of multibyte characters in the character string STRING.
989 This considers multibyte characters, unlike strlen, which counts bytes. */
990 # ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
991 # undef mbslen
992 # endif
993 # if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */
994 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
995 # define mbslen rpl_mbslen
996 # endif
997 _GL_FUNCDECL_RPL (mbslen, size_t, (const char *string)
998 _GL_ATTRIBUTE_PURE
999 _GL_ARG_NONNULL ((1)));
1000 _GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
1001 # else
1002 _GL_FUNCDECL_SYS (mbslen, size_t, (const char *string)
1003 _GL_ATTRIBUTE_PURE
1004 _GL_ARG_NONNULL ((1)));
1005 _GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
1006 # endif
1007 # if __GLIBC__ >= 2
1008 _GL_CXXALIASWARN (mbslen);
1009 # endif
1010 #endif
1011
1012 #if @GNULIB_MBSNLEN@
1013 /* Return the number of multibyte characters in the character string starting
1014 at STRING and ending at STRING + LEN. */
1015 _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
1016 _GL_ATTRIBUTE_PURE
1017 _GL_ARG_NONNULL ((1));
1018 #endif
1019
1020 #if @GNULIB_MBSCHR@
1021 /* Locate the first single-byte character C in the character string STRING,
1022 and return a pointer to it. Return NULL if C is not found in STRING.
1023 Unlike strchr(), this function works correctly in multibyte locales with
1024 encodings such as GB18030. */
1025 # if defined __hpux
1026 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1027 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */
1028 # endif
1029 _GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c)
1030 _GL_ATTRIBUTE_PURE
1031 _GL_ARG_NONNULL ((1)));
1032 _GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
1033 # else
1034 _GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c)
1035 _GL_ATTRIBUTE_PURE
1036 _GL_ARG_NONNULL ((1)));
1037 _GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
1038 # endif
1039 _GL_CXXALIASWARN (mbschr);
1040 #endif
1041
1042 #if @GNULIB_MBSRCHR@
1043 /* Locate the last single-byte character C in the character string STRING,
1044 and return a pointer to it. Return NULL if C is not found in STRING.
1045 Unlike strrchr(), this function works correctly in multibyte locales with
1046 encodings such as GB18030. */
1047 # if defined __hpux || defined __INTERIX
1048 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1049 # define mbsrchr rpl_mbsrchr /* avoid collision with system function */
1050 # endif
1051 _GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c)
1052 _GL_ATTRIBUTE_PURE
1053 _GL_ARG_NONNULL ((1)));
1054 _GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
1055 # else
1056 _GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c)
1057 _GL_ATTRIBUTE_PURE
1058 _GL_ARG_NONNULL ((1)));
1059 _GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
1060 # endif
1061 _GL_CXXALIASWARN (mbsrchr);
1062 #endif
1063
1064 #if @GNULIB_MBSSTR@
1065 /* Find the first occurrence of the character string NEEDLE in the character
1066 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
1067 Unlike strstr(), this function works correctly in multibyte locales with
1068 encodings different from UTF-8. */
1069 _GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
1070 _GL_ATTRIBUTE_PURE
1071 _GL_ARG_NONNULL ((1, 2));
1072 #endif
1073
1074 #if @GNULIB_MBSCASECMP@
1075 /* Compare the character strings S1 and S2, ignoring case, returning less than,
1076 equal to or greater than zero if S1 is lexicographically less than, equal to
1077 or greater than S2.
1078 Note: This function may, in multibyte locales, return 0 for strings of
1079 different lengths!
1080 Unlike strcasecmp(), this function works correctly in multibyte locales. */
1081 _GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2)
1082 _GL_ATTRIBUTE_PURE
1083 _GL_ARG_NONNULL ((1, 2));
1084 #endif
1085
1086 #if @GNULIB_MBSNCASECMP@
1087 /* Compare the initial segment of the character string S1 consisting of at most
1088 N characters with the initial segment of the character string S2 consisting
1089 of at most N characters, ignoring case, returning less than, equal to or
1090 greater than zero if the initial segment of S1 is lexicographically less
1091 than, equal to or greater than the initial segment of S2.
1092 Note: This function may, in multibyte locales, return 0 for initial segments
1093 of different lengths!
1094 Unlike strncasecmp(), this function works correctly in multibyte locales.
1095 But beware that N is not a byte count but a character count! */
1096 _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
1097 _GL_ATTRIBUTE_PURE
1098 _GL_ARG_NONNULL ((1, 2));
1099 #endif
1100
1101 #if @GNULIB_MBSPCASECMP@
1102 /* Compare the initial segment of the character string STRING consisting of
1103 at most mbslen (PREFIX) characters with the character string PREFIX,
1104 ignoring case. If the two match, return a pointer to the first byte
1105 after this prefix in STRING. Otherwise, return NULL.
1106 Note: This function may, in multibyte locales, return non-NULL if STRING
1107 is of smaller length than PREFIX!
1108 Unlike strncasecmp(), this function works correctly in multibyte
1109 locales. */
1110 _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
1111 _GL_ATTRIBUTE_PURE
1112 _GL_ARG_NONNULL ((1, 2));
1113 #endif
1114
1115 #if @GNULIB_MBSCASESTR@
1116 /* Find the first occurrence of the character string NEEDLE in the character
1117 string HAYSTACK, using case-insensitive comparison.
1118 Note: This function may, in multibyte locales, return success even if
1119 strlen (haystack) < strlen (needle) !
1120 Unlike strcasestr(), this function works correctly in multibyte locales. */
1121 _GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
1122 _GL_ATTRIBUTE_PURE
1123 _GL_ARG_NONNULL ((1, 2));
1124 #endif
1125
1126 #if @GNULIB_MBSCSPN@
1127 /* Find the first occurrence in the character string STRING of any character
1128 in the character string ACCEPT. Return the number of bytes from the
1129 beginning of the string to this occurrence, or to the end of the string
1130 if none exists.
1131 Unlike strcspn(), this function works correctly in multibyte locales. */
1132 _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
1133 _GL_ATTRIBUTE_PURE
1134 _GL_ARG_NONNULL ((1, 2));
1135 #endif
1136
1137 #if @GNULIB_MBSPBRK@
1138 /* Find the first occurrence in the character string STRING of any character
1139 in the character string ACCEPT. Return the pointer to it, or NULL if none
1140 exists.
1141 Unlike strpbrk(), this function works correctly in multibyte locales. */
1142 # if defined __hpux
1143 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1144 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1145 # endif
1146 _GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept)
1147 _GL_ATTRIBUTE_PURE
1148 _GL_ARG_NONNULL ((1, 2)));
1149 _GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
1150 # else
1151 _GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept)
1152 _GL_ATTRIBUTE_PURE
1153 _GL_ARG_NONNULL ((1, 2)));
1154 _GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
1155 # endif
1156 _GL_CXXALIASWARN (mbspbrk);
1157 #endif
1158
1159 #if @GNULIB_MBSSPN@
1160 /* Find the first occurrence in the character string STRING of any character
1161 not in the character string REJECT. Return the number of bytes from the
1162 beginning of the string to this occurrence, or to the end of the string
1163 if none exists.
1164 Unlike strspn(), this function works correctly in multibyte locales. */
1165 _GL_EXTERN_C size_t mbsspn (const char *string, const char *reject)
1166 _GL_ATTRIBUTE_PURE
1167 _GL_ARG_NONNULL ((1, 2));
1168 #endif
1169
1170 #if @GNULIB_MBSSEP@
1171 /* Search the next delimiter (multibyte character listed in the character
1172 string DELIM) starting at the character string *STRINGP.
1173 If one is found, overwrite it with a NUL, and advance *STRINGP to point
1174 to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
1175 If *STRINGP was already NULL, nothing happens.
1176 Return the old value of *STRINGP.
1177
1178 This is a variant of mbstok_r() that supports empty fields.
1179
1180 Caveat: It modifies the original string.
1181 Caveat: These functions cannot be used on constant strings.
1182 Caveat: The identity of the delimiting character is lost.
1183
1184 See also mbstok_r(). */
1185 _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
1186 _GL_ARG_NONNULL ((1, 2));
1187 #endif
1188
1189 #if @GNULIB_MBSTOK_R@
1190 /* Parse the character string STRING into tokens separated by characters in
1191 the character string DELIM.
1192 If STRING is NULL, the saved pointer in SAVE_PTR is used as
1193 the next starting point. For example:
1194 char s[] = "-abc-=-def";
1195 char *sp;
1196 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
1197 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
1198 x = mbstok_r(NULL, "=", &sp); // x = NULL
1199 // s = "abc\0-def\0"
1200
1201 Caveat: It modifies the original string.
1202 Caveat: These functions cannot be used on constant strings.
1203 Caveat: The identity of the delimiting character is lost.
1204
1205 See also mbssep(). */
1206 _GL_EXTERN_C char * mbstok_r (char *restrict string, const char *delim,
1207 char **save_ptr)
1208 _GL_ARG_NONNULL ((2, 3));
1209 #endif
1210
1211 /* Map any int, typically from errno, into an error message. */
1212 #if @GNULIB_STRERROR@
1213 # if @REPLACE_STRERROR@
1214 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1215 # undef strerror
1216 # define strerror rpl_strerror
1217 # endif
1218 _GL_FUNCDECL_RPL (strerror, char *, (int));
1219 _GL_CXXALIAS_RPL (strerror, char *, (int));
1220 # else
1221 _GL_CXXALIAS_SYS (strerror, char *, (int));
1222 # endif
1223 # if __GLIBC__ >= 2
1224 _GL_CXXALIASWARN (strerror);
1225 # endif
1226 #elif defined GNULIB_POSIXCHECK
1227 # undef strerror
1228 /* Assume strerror is always declared. */
1229 _GL_WARN_ON_USE (strerror, "strerror is unportable - "
1230 "use gnulib module strerror to guarantee non-NULL result");
1231 #endif
1232
1233 /* Map any int, typically from errno, into an error message. Multithread-safe.
1234 Uses the POSIX declaration, not the glibc declaration. */
1235 #if @GNULIB_STRERROR_R@
1236 # if @REPLACE_STRERROR_R@
1237 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1238 # undef strerror_r
1239 # define strerror_r rpl_strerror_r
1240 # endif
1241 _GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)
1242 _GL_ARG_NONNULL ((2)));
1243 _GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
1244 # else
1245 # if !@HAVE_DECL_STRERROR_R@
1246 _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)
1247 _GL_ARG_NONNULL ((2)));
1248 # endif
1249 _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
1250 # endif
1251 # if __GLIBC__ >= 2 && @HAVE_DECL_STRERROR_R@
1252 _GL_CXXALIASWARN (strerror_r);
1253 # endif
1254 #elif defined GNULIB_POSIXCHECK
1255 # undef strerror_r
1256 # if HAVE_RAW_DECL_STRERROR_R
1257 _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
1258 "use gnulib module strerror_r-posix for portability");
1259 # endif
1260 #endif
1261
1262 /* Return the name of the system error code ERRNUM. */
1263 #if @GNULIB_STRERRORNAME_NP@
1264 # if @REPLACE_STRERRORNAME_NP@
1265 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1266 # undef strerrorname_np
1267 # define strerrorname_np rpl_strerrorname_np
1268 # endif
1269 _GL_FUNCDECL_RPL (strerrorname_np, const char *, (int errnum));
1270 _GL_CXXALIAS_RPL (strerrorname_np, const char *, (int errnum));
1271 # else
1272 # if !@HAVE_STRERRORNAME_NP@
1273 _GL_FUNCDECL_SYS (strerrorname_np, const char *, (int errnum));
1274 # endif
1275 _GL_CXXALIAS_SYS (strerrorname_np, const char *, (int errnum));
1276 # endif
1277 _GL_CXXALIASWARN (strerrorname_np);
1278 #elif defined GNULIB_POSIXCHECK
1279 # undef strerrorname_np
1280 # if HAVE_RAW_DECL_STRERRORNAME_NP
1281 _GL_WARN_ON_USE (strerrorname_np, "strerrorname_np is unportable - "
1282 "use gnulib module strerrorname_np for portability");
1283 # endif
1284 #endif
1285
1286 /* Return an abbreviation string for the signal number SIG. */
1287 #if @GNULIB_SIGABBREV_NP@
1288 # if ! @HAVE_SIGABBREV_NP@
1289 _GL_FUNCDECL_SYS (sigabbrev_np, const char *, (int sig));
1290 # endif
1291 _GL_CXXALIAS_SYS (sigabbrev_np, const char *, (int sig));
1292 _GL_CXXALIASWARN (sigabbrev_np);
1293 #elif defined GNULIB_POSIXCHECK
1294 # undef sigabbrev_np
1295 # if HAVE_RAW_DECL_SIGABBREV_NP
1296 _GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - "
1297 "use gnulib module sigabbrev_np for portability");
1298 # endif
1299 #endif
1300
1301 /* Return an English description string for the signal number SIG. */
1302 #if @GNULIB_SIGDESCR_NP@
1303 # if ! @HAVE_SIGDESCR_NP@
1304 _GL_FUNCDECL_SYS (sigdescr_np, const char *, (int sig));
1305 # endif
1306 _GL_CXXALIAS_SYS (sigdescr_np, const char *, (int sig));
1307 _GL_CXXALIASWARN (sigdescr_np);
1308 #elif defined GNULIB_POSIXCHECK
1309 # undef sigdescr_np
1310 # if HAVE_RAW_DECL_SIGDESCR_NP
1311 _GL_WARN_ON_USE (sigdescr_np, "sigdescr_np is unportable - "
1312 "use gnulib module sigdescr_np for portability");
1313 # endif
1314 #endif
1315
1316 #if @GNULIB_STRSIGNAL@
1317 # if @REPLACE_STRSIGNAL@
1318 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1319 # define strsignal rpl_strsignal
1320 # endif
1321 _GL_FUNCDECL_RPL (strsignal, char *, (int __sig));
1322 _GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
1323 # else
1324 # if ! @HAVE_DECL_STRSIGNAL@
1325 _GL_FUNCDECL_SYS (strsignal, char *, (int __sig));
1326 # endif
1327 /* Need to cast, because on Cygwin 1.5.x systems, the return type is
1328 'const char *'. */
1329 _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
1330 # endif
1331 _GL_CXXALIASWARN (strsignal);
1332 #elif defined GNULIB_POSIXCHECK
1333 # undef strsignal
1334 # if HAVE_RAW_DECL_STRSIGNAL
1335 _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
1336 "use gnulib module strsignal for portability");
1337 # endif
1338 #endif
1339
1340 #if @GNULIB_STRVERSCMP@
1341 # if !@HAVE_STRVERSCMP@
1342 _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *)
1343 _GL_ATTRIBUTE_PURE
1344 _GL_ARG_NONNULL ((1, 2)));
1345 # endif
1346 _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
1347 _GL_CXXALIASWARN (strverscmp);
1348 #elif defined GNULIB_POSIXCHECK
1349 # undef strverscmp
1350 # if HAVE_RAW_DECL_STRVERSCMP
1351 _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1352 "use gnulib module strverscmp for portability");
1353 # endif
1354 #endif
1355
1356
1357 #endif /* _@GUARD_PREFIX@_STRING_H */
1358 #endif /* _@GUARD_PREFIX@_STRING_H */
1359 #endif