Enchant: enchant-2.6.5/lib/string.in.h Source File

Enchant Generic spell checking library

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