Debian Codegraph @

gnulib/lib/string.in.h

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