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