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