summaryrefslogtreecommitdiffstats
path: root/gl/string.in.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/string.in.h')
-rw-r--r--gl/string.in.h555
1 files changed, 429 insertions, 126 deletions
diff --git a/gl/string.in.h b/gl/string.in.h
index 44ec2e7e..b54ec0ca 100644
--- a/gl/string.in.h
+++ b/gl/string.in.h
@@ -1,6 +1,6 @@
1/* A GNU-like <string.h>. 1/* A GNU-like <string.h>.
2 2
3 Copyright (C) 1995-1996, 2001-2024 Free Software Foundation, Inc. 3 Copyright (C) 1995-1996, 2001-2026 Free Software Foundation, Inc.
4 4
5 This file is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU Lesser General Public License as
@@ -20,7 +20,7 @@
20#endif 20#endif
21@PRAGMA_COLUMNS@ 21@PRAGMA_COLUMNS@
22 22
23#if defined _GL_ALREADY_INCLUDING_STRING_H 23#if defined _@GUARD_PREFIX@_ALREADY_INCLUDING_STRING_H
24/* Special invocation convention: 24/* Special invocation convention:
25 - On OS X/NetBSD we have a sequence of nested includes 25 - On OS X/NetBSD we have a sequence of nested includes
26 <string.h> -> <strings.h> -> "string.h" 26 <string.h> -> <strings.h> -> "string.h"
@@ -34,12 +34,12 @@
34 34
35#ifndef _@GUARD_PREFIX@_STRING_H 35#ifndef _@GUARD_PREFIX@_STRING_H
36 36
37#define _GL_ALREADY_INCLUDING_STRING_H 37#define _@GUARD_PREFIX@_ALREADY_INCLUDING_STRING_H
38 38
39/* The include_next requires a split double-inclusion guard. */ 39/* The include_next requires a split double-inclusion guard. */
40#@INCLUDE_NEXT@ @NEXT_STRING_H@ 40#@INCLUDE_NEXT@ @NEXT_STRING_H@
41 41
42#undef _GL_ALREADY_INCLUDING_STRING_H 42#undef _@GUARD_PREFIX@_ALREADY_INCLUDING_STRING_H
43 43
44#ifndef _@GUARD_PREFIX@_STRING_H 44#ifndef _@GUARD_PREFIX@_STRING_H
45#define _@GUARD_PREFIX@_STRING_H 45#define _@GUARD_PREFIX@_STRING_H
@@ -54,6 +54,11 @@
54/* NetBSD 5.0 mis-defines NULL. */ 54/* NetBSD 5.0 mis-defines NULL. */
55#include <stddef.h> 55#include <stddef.h>
56 56
57#if @GNULIB_STRERROR_L@
58/* Get locale_t. */
59# include <locale.h>
60#endif
61
57/* MirBSD defines mbslen as a macro. */ 62/* MirBSD defines mbslen as a macro. */
58#if @GNULIB_MBSLEN@ && defined __MirBSD__ 63#if @GNULIB_MBSLEN@ && defined __MirBSD__
59# include <wchar.h> 64# include <wchar.h>
@@ -75,11 +80,17 @@
75# include <strings.h> 80# include <strings.h>
76#endif 81#endif
77 82
83_GL_INLINE_HEADER_BEGIN
84
85#ifndef _GL_STRING_INLINE
86# define _GL_STRING_INLINE _GL_INLINE
87#endif
88
78/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers 89/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
79 that can be freed by passing them as the Ith argument to the 90 that can be freed by passing them as the Ith argument to the
80 function F. */ 91 function F. */
81#ifndef _GL_ATTRIBUTE_DEALLOC 92#ifndef _GL_ATTRIBUTE_DEALLOC
82# if __GNUC__ >= 11 93# if __GNUC__ >= 11 && !defined __clang__
83# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i))) 94# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
84# else 95# else
85# define _GL_ATTRIBUTE_DEALLOC(f, i) 96# define _GL_ATTRIBUTE_DEALLOC(f, i)
@@ -91,7 +102,7 @@
91/* Applies to: functions. Cannot be used on inline functions. */ 102/* Applies to: functions. Cannot be used on inline functions. */
92#ifndef _GL_ATTRIBUTE_DEALLOC_FREE 103#ifndef _GL_ATTRIBUTE_DEALLOC_FREE
93# if defined __cplusplus && defined __GNUC__ && !defined __clang__ 104# if defined __cplusplus && defined __GNUC__ && !defined __clang__
94/* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */ 105/* Work around GCC bug <https://gcc.gnu.org/PR108231> */
95# define _GL_ATTRIBUTE_DEALLOC_FREE \ 106# define _GL_ATTRIBUTE_DEALLOC_FREE \
96 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1) 107 _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
97# else 108# else
@@ -111,11 +122,23 @@
111# endif 122# endif
112#endif 123#endif
113 124
125/* _GL_ATTRIBUTE_NONNULL_IF_NONZERO (NP, NI) declares that the argument NP
126 (a pointer) must not be NULL if the argument NI (an integer) is != 0. */
127/* Applies to: functions. */
128#ifndef _GL_ATTRIBUTE_NONNULL_IF_NONZERO
129# if __GNUC__ >= 15 && !defined __clang__
130# define _GL_ATTRIBUTE_NONNULL_IF_NONZERO(np, ni) \
131 __attribute__ ((__nonnull_if_nonzero__ (np, ni)))
132# else
133# define _GL_ATTRIBUTE_NONNULL_IF_NONZERO(np, ni)
134# endif
135#endif
136
114/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. 137/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
115 */ 138 */
116#ifndef _GL_ATTRIBUTE_NOTHROW 139#ifndef _GL_ATTRIBUTE_NOTHROW
117# if defined __cplusplus 140# if defined __cplusplus
118# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4 141# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major__ >= 4
119# if __cplusplus >= 201103L 142# if __cplusplus >= 201103L
120# define _GL_ATTRIBUTE_NOTHROW noexcept (true) 143# define _GL_ATTRIBUTE_NOTHROW noexcept (true)
121# else 144# else
@@ -149,6 +172,7 @@
149 172
150/* The definition of _GL_WARN_ON_USE is copied here. */ 173/* The definition of _GL_WARN_ON_USE is copied here. */
151 174
175
152/* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though <stdlib.h> may not have 176/* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though <stdlib.h> may not have
153 been included yet. */ 177 been included yet. */
154#if @GNULIB_FREE_POSIX@ 178#if @GNULIB_FREE_POSIX@
@@ -193,32 +217,116 @@ _GL_EXTERN_C void free (void *);
193# endif 217# endif
194#endif 218#endif
195 219
220
221/* Declarations for ISO C N3322. */
222#if defined __GNUC__ && __GNUC__ >= 15 && !defined __clang__
223# ifndef memcpy
224_GL_EXTERN_C void *memcpy (void *__dest, const void *__src, size_t __n)
225# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
226 _GL_ATTRIBUTE_NOTHROW
227# endif
228 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
229 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
230# endif
231# ifndef memccpy
232_GL_EXTERN_C void *memccpy (void *__dest, const void *__src, int __c, size_t __n)
233# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
234 _GL_ATTRIBUTE_NOTHROW
235# endif
236 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 4)
237 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 4);
238# endif
239# ifndef memmove
240_GL_EXTERN_C void *memmove (void *__dest, const void *__src, size_t __n)
241# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
242 _GL_ATTRIBUTE_NOTHROW
243# endif
244 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
245 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
246# endif
247# ifndef strncpy
248_GL_EXTERN_C char *strncpy (char *__dest, const char *__src, size_t __n)
249# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
250 _GL_ATTRIBUTE_NOTHROW
251# endif
252 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
253 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
254# endif
255# ifndef strndup
256_GL_EXTERN_C char *strndup (const char *__s, size_t __n)
257# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
258 _GL_ATTRIBUTE_NOTHROW
259# endif
260 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2);
261# endif
262# ifndef strncat
263_GL_EXTERN_C char *strncat (char *__dest, const char *__src, size_t __n)
264# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
265 _GL_ATTRIBUTE_NOTHROW
266# endif
267 _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
268# endif
269# ifndef memcmp
270_GL_EXTERN_C int memcmp (const void *__s1, const void *__s2, size_t __n)
271# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
272 _GL_ATTRIBUTE_NOTHROW
273# endif
274 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
275 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
276# endif
277# ifndef strncmp
278_GL_EXTERN_C int strncmp (const char *__s1, const char *__s2, size_t __n)
279# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
280 _GL_ATTRIBUTE_NOTHROW
281# endif
282 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3)
283 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3);
284# endif
285# if !defined memchr && !defined __cplusplus
286_GL_EXTERN_C void *memchr (const void *__s, int __c, size_t __n)
287 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3);
288_GL_EXTERN_C void *memrchr (const void *__s, int __c, size_t __n)
289 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3);
290# endif
291# ifndef memset
292_GL_EXTERN_C void *memset (void *__s, int __c, size_t __n)
293# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
294 _GL_ATTRIBUTE_NOTHROW
295# endif
296 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3);
297# endif
298# ifndef memset_explicit
299_GL_EXTERN_C void *memset_explicit (void *__s, int __c, size_t __n)
300 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3);
301# endif
302#endif
303
304
196/* Clear a block of memory. The compiler will not delete a call to 305/* Clear a block of memory. The compiler will not delete a call to
197 this function, even if the block is dead after the call. */ 306 this function, even if the block is dead after the call. */
198#if @GNULIB_EXPLICIT_BZERO@ 307#if @GNULIB_EXPLICIT_BZERO@
199# if ! @HAVE_EXPLICIT_BZERO@ 308# if ! @HAVE_EXPLICIT_BZERO@
200_GL_FUNCDECL_SYS (explicit_bzero, void, 309_GL_FUNCDECL_SYS (explicit_bzero, void,
201 (void *__dest, size_t __n) _GL_ARG_NONNULL ((1))); 310 (void *__dest, size_t __n), _GL_ARG_NONNULL ((1)));
202# endif 311# endif
203_GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n)); 312_GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n));
204_GL_CXXALIASWARN (explicit_bzero); 313_GL_CXXALIASWARN (explicit_bzero);
205#elif defined GNULIB_POSIXCHECK 314#elif defined GNULIB_POSIXCHECK
206# undef explicit_bzero
207# if HAVE_RAW_DECL_EXPLICIT_BZERO 315# if HAVE_RAW_DECL_EXPLICIT_BZERO
208_GL_WARN_ON_USE (explicit_bzero, "explicit_bzero is unportable - " 316_GL_WARN_ON_USE (explicit_bzero, "explicit_bzero is unportable - "
209 "use gnulib module explicit_bzero for portability"); 317 "use gnulib module explicit_bzero for portability");
210# endif 318# endif
211#endif 319#endif
212 320
321
213/* Find the index of the least-significant set bit. */ 322/* Find the index of the least-significant set bit. */
214#if @GNULIB_FFSL@ 323#if @GNULIB_FFSL@
215# if !@HAVE_FFSL@ 324# if !@HAVE_FFSL@
216_GL_FUNCDECL_SYS (ffsl, int, (long int i)); 325_GL_FUNCDECL_SYS (ffsl, int, (long int i), );
217# endif 326# endif
218_GL_CXXALIAS_SYS (ffsl, int, (long int i)); 327_GL_CXXALIAS_SYS (ffsl, int, (long int i));
219_GL_CXXALIASWARN (ffsl); 328_GL_CXXALIASWARN (ffsl);
220#elif defined GNULIB_POSIXCHECK 329#elif defined GNULIB_POSIXCHECK
221# undef ffsl
222# if HAVE_RAW_DECL_FFSL 330# if HAVE_RAW_DECL_FFSL
223_GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module"); 331_GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
224# endif 332# endif
@@ -231,17 +339,16 @@ _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
231# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 339# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
232# define ffsll rpl_ffsll 340# define ffsll rpl_ffsll
233# endif 341# endif
234_GL_FUNCDECL_RPL (ffsll, int, (long long int i)); 342_GL_FUNCDECL_RPL (ffsll, int, (long long int i), );
235_GL_CXXALIAS_RPL (ffsll, int, (long long int i)); 343_GL_CXXALIAS_RPL (ffsll, int, (long long int i));
236# else 344# else
237# if !@HAVE_FFSLL@ 345# if !@HAVE_FFSLL@
238_GL_FUNCDECL_SYS (ffsll, int, (long long int i)); 346_GL_FUNCDECL_SYS (ffsll, int, (long long int i), );
239# endif 347# endif
240_GL_CXXALIAS_SYS (ffsll, int, (long long int i)); 348_GL_CXXALIAS_SYS (ffsll, int, (long long int i));
241# endif 349# endif
242_GL_CXXALIASWARN (ffsll); 350_GL_CXXALIASWARN (ffsll);
243#elif defined GNULIB_POSIXCHECK 351#elif defined GNULIB_POSIXCHECK
244# undef ffsll
245# if HAVE_RAW_DECL_FFSLL 352# if HAVE_RAW_DECL_FFSLL
246_GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module"); 353_GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
247# endif 354# endif
@@ -274,9 +381,9 @@ _GL_CXXALIASWARN (memccpy);
274# undef memchr 381# undef memchr
275# define memchr rpl_memchr 382# define memchr rpl_memchr
276# endif 383# endif
277_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) 384_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n),
278 _GL_ATTRIBUTE_PURE 385 _GL_ATTRIBUTE_PURE
279 _GL_ARG_NONNULL ((1))); 386 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3));
280_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n)); 387_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
281# else 388# else
282 /* On some systems, this function is defined as an overloaded function: 389 /* On some systems, this function is defined as an overloaded function:
@@ -299,10 +406,26 @@ _GL_CXXALIASWARN1 (memchr, void const *,
299_GL_CXXALIASWARN (memchr); 406_GL_CXXALIASWARN (memchr);
300# endif 407# endif
301#elif defined GNULIB_POSIXCHECK 408#elif defined GNULIB_POSIXCHECK
302# undef memchr
303/* Assume memchr is always declared. */ 409/* Assume memchr is always declared. */
304_GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - " 410_GL_WARN_ON_USE_CXX (memchr,
305 "use gnulib module memchr for portability" ); 411 const void *, void *, (void const *, int, size_t),
412 "memchr has platform-specific bugs - "
413 "use gnulib module memchr for portability" );
414#endif
415
416/* Are S1 and S2, of size N, bytewise equal? */
417#if @GNULIB_STRINGEQ@ && !@HAVE_DECL_MEMEQ@
418# ifdef __cplusplus
419extern "C" {
420# endif
421_GL_STRING_INLINE bool
422memeq (void const *__s1, void const *__s2, size_t __n)
423{
424 return !memcmp (__s1, __s2, __n);
425}
426# ifdef __cplusplus
427}
428# endif
306#endif 429#endif
307 430
308/* Return the first occurrence of NEEDLE in HAYSTACK. */ 431/* Return the first occurrence of NEEDLE in HAYSTACK. */
@@ -313,7 +436,7 @@ _GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - "
313# endif 436# endif
314_GL_FUNCDECL_RPL (memmem, void *, 437_GL_FUNCDECL_RPL (memmem, void *,
315 (void const *__haystack, size_t __haystack_len, 438 (void const *__haystack, size_t __haystack_len,
316 void const *__needle, size_t __needle_len) 439 void const *__needle, size_t __needle_len),
317 _GL_ATTRIBUTE_PURE 440 _GL_ATTRIBUTE_PURE
318 _GL_ARG_NONNULL ((1, 3))); 441 _GL_ARG_NONNULL ((1, 3)));
319_GL_CXXALIAS_RPL (memmem, void *, 442_GL_CXXALIAS_RPL (memmem, void *,
@@ -323,7 +446,7 @@ _GL_CXXALIAS_RPL (memmem, void *,
323# if ! @HAVE_DECL_MEMMEM@ 446# if ! @HAVE_DECL_MEMMEM@
324_GL_FUNCDECL_SYS (memmem, void *, 447_GL_FUNCDECL_SYS (memmem, void *,
325 (void const *__haystack, size_t __haystack_len, 448 (void const *__haystack, size_t __haystack_len,
326 void const *__needle, size_t __needle_len) 449 void const *__needle, size_t __needle_len),
327 _GL_ATTRIBUTE_PURE 450 _GL_ATTRIBUTE_PURE
328 _GL_ARG_NONNULL ((1, 3))); 451 _GL_ARG_NONNULL ((1, 3)));
329# endif 452# endif
@@ -333,7 +456,6 @@ _GL_CXXALIAS_SYS (memmem, void *,
333# endif 456# endif
334_GL_CXXALIASWARN (memmem); 457_GL_CXXALIASWARN (memmem);
335#elif defined GNULIB_POSIXCHECK 458#elif defined GNULIB_POSIXCHECK
336# undef memmem
337# if HAVE_RAW_DECL_MEMMEM 459# if HAVE_RAW_DECL_MEMMEM
338_GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - " 460_GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
339 "use gnulib module memmem-simple for portability, " 461 "use gnulib module memmem-simple for portability, "
@@ -351,7 +473,7 @@ _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - "
351# endif 473# endif
352_GL_FUNCDECL_RPL (mempcpy, void *, 474_GL_FUNCDECL_RPL (mempcpy, void *,
353 (void *restrict __dest, void const *restrict __src, 475 (void *restrict __dest, void const *restrict __src,
354 size_t __n) 476 size_t __n),
355 _GL_ARG_NONNULL ((1, 2))); 477 _GL_ARG_NONNULL ((1, 2)));
356_GL_CXXALIAS_RPL (mempcpy, void *, 478_GL_CXXALIAS_RPL (mempcpy, void *,
357 (void *restrict __dest, void const *restrict __src, 479 (void *restrict __dest, void const *restrict __src,
@@ -360,7 +482,7 @@ _GL_CXXALIAS_RPL (mempcpy, void *,
360# if !@HAVE_MEMPCPY@ 482# if !@HAVE_MEMPCPY@
361_GL_FUNCDECL_SYS (mempcpy, void *, 483_GL_FUNCDECL_SYS (mempcpy, void *,
362 (void *restrict __dest, void const *restrict __src, 484 (void *restrict __dest, void const *restrict __src,
363 size_t __n) 485 size_t __n),
364 _GL_ARG_NONNULL ((1, 2))); 486 _GL_ARG_NONNULL ((1, 2)));
365# endif 487# endif
366_GL_CXXALIAS_SYS (mempcpy, void *, 488_GL_CXXALIAS_SYS (mempcpy, void *,
@@ -371,7 +493,6 @@ _GL_CXXALIAS_SYS (mempcpy, void *,
371_GL_CXXALIASWARN (mempcpy); 493_GL_CXXALIASWARN (mempcpy);
372# endif 494# endif
373#elif defined GNULIB_POSIXCHECK 495#elif defined GNULIB_POSIXCHECK
374# undef mempcpy
375# if HAVE_RAW_DECL_MEMPCPY 496# if HAVE_RAW_DECL_MEMPCPY
376_GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - " 497_GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
377 "use gnulib module mempcpy for portability"); 498 "use gnulib module mempcpy for portability");
@@ -381,9 +502,9 @@ _GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - "
381/* Search backwards through a block for a byte (specified as an int). */ 502/* Search backwards through a block for a byte (specified as an int). */
382#if @GNULIB_MEMRCHR@ 503#if @GNULIB_MEMRCHR@
383# if ! @HAVE_DECL_MEMRCHR@ 504# if ! @HAVE_DECL_MEMRCHR@
384_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t) 505_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t),
385 _GL_ATTRIBUTE_PURE 506 _GL_ATTRIBUTE_PURE
386 _GL_ARG_NONNULL ((1))); 507 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3));
387# endif 508# endif
388 /* On some systems, this function is defined as an overloaded function: 509 /* On some systems, this function is defined as an overloaded function:
389 extern "C++" { const void * std::memrchr (const void *, int, size_t); } 510 extern "C++" { const void * std::memrchr (const void *, int, size_t); }
@@ -404,7 +525,6 @@ _GL_CXXALIASWARN1 (memrchr, void const *,
404_GL_CXXALIASWARN (memrchr); 525_GL_CXXALIASWARN (memrchr);
405# endif 526# endif
406#elif defined GNULIB_POSIXCHECK 527#elif defined GNULIB_POSIXCHECK
407# undef memrchr
408# if HAVE_RAW_DECL_MEMRCHR 528# if HAVE_RAW_DECL_MEMRCHR
409_GL_WARN_ON_USE (memrchr, "memrchr is unportable - " 529_GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
410 "use gnulib module memrchr for portability"); 530 "use gnulib module memrchr for portability");
@@ -420,18 +540,21 @@ _GL_WARN_ON_USE (memrchr, "memrchr is unportable - "
420# define memset_explicit rpl_memset_explicit 540# define memset_explicit rpl_memset_explicit
421# endif 541# endif
422_GL_FUNCDECL_RPL (memset_explicit, void *, 542_GL_FUNCDECL_RPL (memset_explicit, void *,
423 (void *__dest, int __c, size_t __n) _GL_ARG_NONNULL ((1))); 543 (void *__dest, int __c, size_t __n),
544 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3));
424_GL_CXXALIAS_RPL (memset_explicit, void *, (void *__dest, int __c, size_t __n)); 545_GL_CXXALIAS_RPL (memset_explicit, void *, (void *__dest, int __c, size_t __n));
425# else 546# else
426# if !@HAVE_MEMSET_EXPLICIT@ 547# if !@HAVE_MEMSET_EXPLICIT@
427_GL_FUNCDECL_SYS (memset_explicit, void *, 548_GL_FUNCDECL_SYS (memset_explicit, void *,
428 (void *__dest, int __c, size_t __n) _GL_ARG_NONNULL ((1))); 549 (void *__dest, int __c, size_t __n),
550 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 3));
429# endif 551# endif
430_GL_CXXALIAS_SYS (memset_explicit, void *, (void *__dest, int __c, size_t __n)); 552_GL_CXXALIAS_SYS (memset_explicit, void *, (void *__dest, int __c, size_t __n));
431# endif 553# endif
554# if __GLIBC__ >= 2
432_GL_CXXALIASWARN (memset_explicit); 555_GL_CXXALIASWARN (memset_explicit);
556# endif
433#elif defined GNULIB_POSIXCHECK 557#elif defined GNULIB_POSIXCHECK
434# undef memset_explicit
435# if HAVE_RAW_DECL_MEMSET_EXPLICIT 558# if HAVE_RAW_DECL_MEMSET_EXPLICIT
436_GL_WARN_ON_USE (memset_explicit, "memset_explicit is unportable - " 559_GL_WARN_ON_USE (memset_explicit, "memset_explicit is unportable - "
437 "use gnulib module memset_explicit for portability"); 560 "use gnulib module memset_explicit for portability");
@@ -443,7 +566,7 @@ _GL_WARN_ON_USE (memset_explicit, "memset_explicit is unportable - "
443 occur within N bytes. */ 566 occur within N bytes. */
444#if @GNULIB_RAWMEMCHR@ 567#if @GNULIB_RAWMEMCHR@
445# if ! @HAVE_RAWMEMCHR@ 568# if ! @HAVE_RAWMEMCHR@
446_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in) 569_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in),
447 _GL_ATTRIBUTE_PURE 570 _GL_ATTRIBUTE_PURE
448 _GL_ARG_NONNULL ((1))); 571 _GL_ARG_NONNULL ((1)));
449# endif 572# endif
@@ -466,7 +589,6 @@ _GL_CXXALIASWARN1 (rawmemchr, void const *,
466_GL_CXXALIASWARN (rawmemchr); 589_GL_CXXALIASWARN (rawmemchr);
467# endif 590# endif
468#elif defined GNULIB_POSIXCHECK 591#elif defined GNULIB_POSIXCHECK
469# undef rawmemchr
470# if HAVE_RAW_DECL_RAWMEMCHR 592# if HAVE_RAW_DECL_RAWMEMCHR
471_GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - " 593_GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
472 "use gnulib module rawmemchr for portability"); 594 "use gnulib module rawmemchr for portability");
@@ -481,14 +603,14 @@ _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - "
481# define stpcpy rpl_stpcpy 603# define stpcpy rpl_stpcpy
482# endif 604# endif
483_GL_FUNCDECL_RPL (stpcpy, char *, 605_GL_FUNCDECL_RPL (stpcpy, char *,
484 (char *restrict __dst, char const *restrict __src) 606 (char *restrict __dst, char const *restrict __src),
485 _GL_ARG_NONNULL ((1, 2))); 607 _GL_ARG_NONNULL ((1, 2)));
486_GL_CXXALIAS_RPL (stpcpy, char *, 608_GL_CXXALIAS_RPL (stpcpy, char *,
487 (char *restrict __dst, char const *restrict __src)); 609 (char *restrict __dst, char const *restrict __src));
488# else 610# else
489# if !@HAVE_STPCPY@ 611# if !@HAVE_STPCPY@
490_GL_FUNCDECL_SYS (stpcpy, char *, 612_GL_FUNCDECL_SYS (stpcpy, char *,
491 (char *restrict __dst, char const *restrict __src) 613 (char *restrict __dst, char const *restrict __src),
492 _GL_ARG_NONNULL ((1, 2))); 614 _GL_ARG_NONNULL ((1, 2)));
493# endif 615# endif
494_GL_CXXALIAS_SYS (stpcpy, char *, 616_GL_CXXALIAS_SYS (stpcpy, char *,
@@ -498,7 +620,6 @@ _GL_CXXALIAS_SYS (stpcpy, char *,
498_GL_CXXALIASWARN (stpcpy); 620_GL_CXXALIASWARN (stpcpy);
499# endif 621# endif
500#elif defined GNULIB_POSIXCHECK 622#elif defined GNULIB_POSIXCHECK
501# undef stpcpy
502# if HAVE_RAW_DECL_STPCPY 623# if HAVE_RAW_DECL_STPCPY
503_GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - " 624_GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
504 "use gnulib module stpcpy for portability"); 625 "use gnulib module stpcpy for portability");
@@ -515,7 +636,7 @@ _GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - "
515# endif 636# endif
516_GL_FUNCDECL_RPL (stpncpy, char *, 637_GL_FUNCDECL_RPL (stpncpy, char *,
517 (char *restrict __dst, char const *restrict __src, 638 (char *restrict __dst, char const *restrict __src,
518 size_t __n) 639 size_t __n),
519 _GL_ARG_NONNULL ((1, 2))); 640 _GL_ARG_NONNULL ((1, 2)));
520_GL_CXXALIAS_RPL (stpncpy, char *, 641_GL_CXXALIAS_RPL (stpncpy, char *,
521 (char *restrict __dst, char const *restrict __src, 642 (char *restrict __dst, char const *restrict __src,
@@ -524,7 +645,7 @@ _GL_CXXALIAS_RPL (stpncpy, char *,
524# if ! @HAVE_STPNCPY@ 645# if ! @HAVE_STPNCPY@
525_GL_FUNCDECL_SYS (stpncpy, char *, 646_GL_FUNCDECL_SYS (stpncpy, char *,
526 (char *restrict __dst, char const *restrict __src, 647 (char *restrict __dst, char const *restrict __src,
527 size_t __n) 648 size_t __n),
528 _GL_ARG_NONNULL ((1, 2))); 649 _GL_ARG_NONNULL ((1, 2)));
529# endif 650# endif
530_GL_CXXALIAS_SYS (stpncpy, char *, 651_GL_CXXALIAS_SYS (stpncpy, char *,
@@ -535,7 +656,6 @@ _GL_CXXALIAS_SYS (stpncpy, char *,
535_GL_CXXALIASWARN (stpncpy); 656_GL_CXXALIASWARN (stpncpy);
536# endif 657# endif
537#elif defined GNULIB_POSIXCHECK 658#elif defined GNULIB_POSIXCHECK
538# undef stpncpy
539# if HAVE_RAW_DECL_STPNCPY 659# if HAVE_RAW_DECL_STPNCPY
540_GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - " 660_GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
541 "use gnulib module stpncpy for portability"); 661 "use gnulib module stpncpy for portability");
@@ -545,7 +665,6 @@ _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
545#if defined GNULIB_POSIXCHECK 665#if defined GNULIB_POSIXCHECK
546/* strchr() does not work with multibyte strings if the locale encoding is 666/* strchr() does not work with multibyte strings if the locale encoding is
547 GB18030 and the character to be searched is a digit. */ 667 GB18030 and the character to be searched is a digit. */
548# undef strchr
549/* Assume strchr is always declared. */ 668/* Assume strchr is always declared. */
550_GL_WARN_ON_USE_CXX (strchr, 669_GL_WARN_ON_USE_CXX (strchr,
551 const char *, char *, (const char *, int), 670 const char *, char *, (const char *, int),
@@ -560,14 +679,14 @@ _GL_WARN_ON_USE_CXX (strchr,
560# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 679# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
561# define strchrnul rpl_strchrnul 680# define strchrnul rpl_strchrnul
562# endif 681# endif
563_GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in) 682_GL_FUNCDECL_RPL (strchrnul, char *, (const char *__s, int __c_in),
564 _GL_ATTRIBUTE_PURE 683 _GL_ATTRIBUTE_PURE
565 _GL_ARG_NONNULL ((1))); 684 _GL_ARG_NONNULL ((1)));
566_GL_CXXALIAS_RPL (strchrnul, char *, 685_GL_CXXALIAS_RPL (strchrnul, char *,
567 (const char *str, int ch)); 686 (const char *str, int ch));
568# else 687# else
569# if ! @HAVE_STRCHRNUL@ 688# if ! @HAVE_STRCHRNUL@
570_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in) 689_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in),
571 _GL_ATTRIBUTE_PURE 690 _GL_ATTRIBUTE_PURE
572 _GL_ARG_NONNULL ((1))); 691 _GL_ARG_NONNULL ((1)));
573# endif 692# endif
@@ -591,7 +710,6 @@ _GL_CXXALIASWARN1 (strchrnul, char const *,
591_GL_CXXALIASWARN (strchrnul); 710_GL_CXXALIASWARN (strchrnul);
592# endif 711# endif
593#elif defined GNULIB_POSIXCHECK 712#elif defined GNULIB_POSIXCHECK
594# undef strchrnul
595# if HAVE_RAW_DECL_STRCHRNUL 713# if HAVE_RAW_DECL_STRCHRNUL
596_GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - " 714_GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
597 "use gnulib module strchrnul for portability"); 715 "use gnulib module strchrnul for portability");
@@ -606,7 +724,7 @@ _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
606# define strdup rpl_strdup 724# define strdup rpl_strdup
607# endif 725# endif
608_GL_FUNCDECL_RPL (strdup, char *, 726_GL_FUNCDECL_RPL (strdup, char *,
609 (char const *__s) 727 (char const *__s),
610 _GL_ARG_NONNULL ((1)) 728 _GL_ARG_NONNULL ((1))
611 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 729 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
612_GL_CXXALIAS_RPL (strdup, char *, (char const *__s)); 730_GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
@@ -621,16 +739,17 @@ _GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
621 /* strdup exists as a function and as a macro. Get rid of the macro. */ 739 /* strdup exists as a function and as a macro. Get rid of the macro. */
622# undef strdup 740# undef strdup
623# endif 741# endif
624# if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup 742# if (!@HAVE_DECL_STRDUP@ || (__GNUC__ >= 11 && !defined __clang__)) \
743 && !defined strdup
625# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 744# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
626_GL_FUNCDECL_SYS (strdup, char *, 745_GL_FUNCDECL_SYS (strdup, char *,
627 (char const *__s) 746 (char const *__s),
628 _GL_ATTRIBUTE_NOTHROW
629 _GL_ARG_NONNULL ((1)) 747 _GL_ARG_NONNULL ((1))
630 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 748 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE)
749 _GL_ATTRIBUTE_NOTHROW;
631# else 750# else
632_GL_FUNCDECL_SYS (strdup, char *, 751_GL_FUNCDECL_SYS (strdup, char *,
633 (char const *__s) 752 (char const *__s),
634 _GL_ARG_NONNULL ((1)) 753 _GL_ARG_NONNULL ((1))
635 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 754 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
636# endif 755# endif
@@ -639,23 +758,22 @@ _GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
639# endif 758# endif
640_GL_CXXALIASWARN (strdup); 759_GL_CXXALIASWARN (strdup);
641#else 760#else
642# if __GNUC__ >= 11 && !defined strdup 761# if (__GNUC__ >= 11 && !defined __clang__) && !defined strdup
643/* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */ 762/* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */
644# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 763# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
645_GL_FUNCDECL_SYS (strdup, char *, 764_GL_FUNCDECL_SYS (strdup, char *,
646 (char const *__s) 765 (char const *__s),
647 _GL_ATTRIBUTE_NOTHROW
648 _GL_ARG_NONNULL ((1)) 766 _GL_ARG_NONNULL ((1))
649 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 767 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE)
768 _GL_ATTRIBUTE_NOTHROW;
650# else 769# else
651_GL_FUNCDECL_SYS (strdup, char *, 770_GL_FUNCDECL_SYS (strdup, char *,
652 (char const *__s) 771 (char const *__s),
653 _GL_ARG_NONNULL ((1)) 772 _GL_ARG_NONNULL ((1))
654 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 773 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
655# endif 774# endif
656# endif 775# endif
657# if defined GNULIB_POSIXCHECK 776# if defined GNULIB_POSIXCHECK
658# undef strdup
659# if HAVE_RAW_DECL_STRDUP 777# if HAVE_RAW_DECL_STRDUP
660_GL_WARN_ON_USE (strdup, "strdup is unportable - " 778_GL_WARN_ON_USE (strdup, "strdup is unportable - "
661 "use gnulib module strdup for portability"); 779 "use gnulib module strdup for portability");
@@ -680,6 +798,21 @@ _GL_CXXALIASWARN (strdup);
680# endif 798# endif
681#endif 799#endif
682 800
801/* Are strings S1 and S2 equal? */
802#if @GNULIB_STRINGEQ@ && !@HAVE_DECL_STREQ@
803# ifdef __cplusplus
804extern "C" {
805# endif
806_GL_STRING_INLINE bool
807streq (char const *__s1, char const *__s2)
808{
809 return !strcmp (__s1, __s2);
810}
811# ifdef __cplusplus
812}
813# endif
814#endif
815
683/* Append no more than N characters from SRC onto DEST. */ 816/* Append no more than N characters from SRC onto DEST. */
684#if @GNULIB_STRNCAT@ 817#if @GNULIB_STRNCAT@
685# if @REPLACE_STRNCAT@ 818# if @REPLACE_STRNCAT@
@@ -688,8 +821,9 @@ _GL_CXXALIASWARN (strdup);
688# define strncat rpl_strncat 821# define strncat rpl_strncat
689# endif 822# endif
690_GL_FUNCDECL_RPL (strncat, char *, 823_GL_FUNCDECL_RPL (strncat, char *,
691 (char *restrict dest, const char *restrict src, size_t n) 824 (char *restrict dest, const char *restrict src, size_t n),
692 _GL_ARG_NONNULL ((1, 2))); 825 _GL_ARG_NONNULL ((1))
826 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 3));
693_GL_CXXALIAS_RPL (strncat, char *, 827_GL_CXXALIAS_RPL (strncat, char *,
694 (char *restrict dest, const char *restrict src, size_t n)); 828 (char *restrict dest, const char *restrict src, size_t n));
695# else 829# else
@@ -700,13 +834,41 @@ _GL_CXXALIAS_SYS (strncat, char *,
700_GL_CXXALIASWARN (strncat); 834_GL_CXXALIASWARN (strncat);
701# endif 835# endif
702#elif defined GNULIB_POSIXCHECK 836#elif defined GNULIB_POSIXCHECK
703# undef strncat
704# if HAVE_RAW_DECL_STRNCAT 837# if HAVE_RAW_DECL_STRNCAT
705_GL_WARN_ON_USE (strncat, "strncat is unportable - " 838_GL_WARN_ON_USE (strncat, "strncat is unportable - "
706 "use gnulib module strncat for portability"); 839 "use gnulib module strncat for portability");
707# endif 840# endif
708#endif 841#endif
709 842
843/* Copy no more than N bytes of SRC to DST, returning DST. */
844#if @GNULIB_STRNCPY@
845# if @REPLACE_STRNCPY@
846# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
847# undef strncpy
848# define strncpy rpl_strncpy
849# endif
850_GL_FUNCDECL_RPL (strncpy, char *,
851 (char *restrict __dst, char const *restrict __src,
852 size_t __n),
853 _GL_ARG_NONNULL ((1, 2)));
854_GL_CXXALIAS_RPL (strncpy, char *,
855 (char *restrict __dst, char const *restrict __src,
856 size_t __n));
857# else
858_GL_CXXALIAS_SYS (strncpy, char *,
859 (char *restrict __dst, char const *restrict __src,
860 size_t __n));
861# endif
862# if __GLIBC__ >= 2
863_GL_CXXALIASWARN (strncpy);
864# endif
865#elif defined GNULIB_POSIXCHECK
866# if HAVE_RAW_DECL_STRNCPY
867_GL_WARN_ON_USE (strncpy, "strncpy is unportable - "
868 "use gnulib module strncpy for portability");
869# endif
870#endif
871
710/* Return a newly allocated copy of at most N bytes of STRING. */ 872/* Return a newly allocated copy of at most N bytes of STRING. */
711#if @GNULIB_STRNDUP@ 873#if @GNULIB_STRNDUP@
712# if @REPLACE_STRNDUP@ 874# if @REPLACE_STRNDUP@
@@ -715,22 +877,23 @@ _GL_WARN_ON_USE (strncat, "strncat is unportable - "
715# define strndup rpl_strndup 877# define strndup rpl_strndup
716# endif 878# endif
717_GL_FUNCDECL_RPL (strndup, char *, 879_GL_FUNCDECL_RPL (strndup, char *,
718 (char const *__s, size_t __n) 880 (char const *__s, size_t __n),
719 _GL_ARG_NONNULL ((1)) 881 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
720 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 882 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
721_GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n)); 883_GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n));
722# else 884# else
723# if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined strndup) 885# if !@HAVE_DECL_STRNDUP@ \
886 || ((__GNUC__ >= 11 && !defined __clang__) && !defined strndup)
724# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 887# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
725_GL_FUNCDECL_SYS (strndup, char *, 888_GL_FUNCDECL_SYS (strndup, char *,
726 (char const *__s, size_t __n) 889 (char const *__s, size_t __n),
727 _GL_ATTRIBUTE_NOTHROW 890 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
728 _GL_ARG_NONNULL ((1)) 891 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE)
729 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 892 _GL_ATTRIBUTE_NOTHROW;
730# else 893# else
731_GL_FUNCDECL_SYS (strndup, char *, 894_GL_FUNCDECL_SYS (strndup, char *,
732 (char const *__s, size_t __n) 895 (char const *__s, size_t __n),
733 _GL_ARG_NONNULL ((1)) 896 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
734 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 897 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
735# endif 898# endif
736# endif 899# endif
@@ -738,23 +901,22 @@ _GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n));
738# endif 901# endif
739_GL_CXXALIASWARN (strndup); 902_GL_CXXALIASWARN (strndup);
740#else 903#else
741# if __GNUC__ >= 11 && !defined strndup 904# if (__GNUC__ >= 11 && !defined __clang__) && !defined strndup
742/* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */ 905/* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */
743# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 906# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
744_GL_FUNCDECL_SYS (strndup, char *, 907_GL_FUNCDECL_SYS (strndup, char *,
745 (char const *__s, size_t __n) 908 (char const *__s, size_t __n),
746 _GL_ATTRIBUTE_NOTHROW 909 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
747 _GL_ARG_NONNULL ((1)) 910 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE)
748 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 911 _GL_ATTRIBUTE_NOTHROW;
749# else 912# else
750_GL_FUNCDECL_SYS (strndup, char *, 913_GL_FUNCDECL_SYS (strndup, char *,
751 (char const *__s, size_t __n) 914 (char const *__s, size_t __n),
752 _GL_ARG_NONNULL ((1)) 915 _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2)
753 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); 916 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
754# endif 917# endif
755# endif 918# endif
756# if defined GNULIB_POSIXCHECK 919# if defined GNULIB_POSIXCHECK
757# undef strndup
758# if HAVE_RAW_DECL_STRNDUP 920# if HAVE_RAW_DECL_STRNDUP
759_GL_WARN_ON_USE (strndup, "strndup is unportable - " 921_GL_WARN_ON_USE (strndup, "strndup is unportable - "
760 "use gnulib module strndup for portability"); 922 "use gnulib module strndup for portability");
@@ -771,13 +933,13 @@ _GL_WARN_ON_USE (strndup, "strndup is unportable - "
771# undef strnlen 933# undef strnlen
772# define strnlen rpl_strnlen 934# define strnlen rpl_strnlen
773# endif 935# endif
774_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen) 936_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen),
775 _GL_ATTRIBUTE_PURE 937 _GL_ATTRIBUTE_PURE
776 _GL_ARG_NONNULL ((1))); 938 _GL_ARG_NONNULL ((1)));
777_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen)); 939_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen));
778# else 940# else
779# if ! @HAVE_DECL_STRNLEN@ 941# if ! @HAVE_DECL_STRNLEN@
780_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen) 942_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen),
781 _GL_ATTRIBUTE_PURE 943 _GL_ATTRIBUTE_PURE
782 _GL_ARG_NONNULL ((1))); 944 _GL_ARG_NONNULL ((1)));
783# endif 945# endif
@@ -785,7 +947,6 @@ _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__s, size_t __maxlen));
785# endif 947# endif
786_GL_CXXALIASWARN (strnlen); 948_GL_CXXALIASWARN (strnlen);
787#elif defined GNULIB_POSIXCHECK 949#elif defined GNULIB_POSIXCHECK
788# undef strnlen
789# if HAVE_RAW_DECL_STRNLEN 950# if HAVE_RAW_DECL_STRNLEN
790_GL_WARN_ON_USE (strnlen, "strnlen is unportable - " 951_GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
791 "use gnulib module strnlen for portability"); 952 "use gnulib module strnlen for portability");
@@ -797,7 +958,6 @@ _GL_WARN_ON_USE (strnlen, "strnlen is unportable - "
797 Even in this simple case, it does not work with multibyte strings if the 958 Even in this simple case, it does not work with multibyte strings if the
798 locale encoding is GB18030 and one of the characters to be searched is a 959 locale encoding is GB18030 and one of the characters to be searched is a
799 digit. */ 960 digit. */
800# undef strcspn
801/* Assume strcspn is always declared. */ 961/* Assume strcspn is always declared. */
802_GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings " 962_GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
803 "in multibyte locales - " 963 "in multibyte locales - "
@@ -807,7 +967,7 @@ _GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings "
807/* Find the first occurrence in S of any character in ACCEPT. */ 967/* Find the first occurrence in S of any character in ACCEPT. */
808#if @GNULIB_STRPBRK@ 968#if @GNULIB_STRPBRK@
809# if ! @HAVE_STRPBRK@ 969# if ! @HAVE_STRPBRK@
810_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept) 970_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept),
811 _GL_ATTRIBUTE_PURE 971 _GL_ATTRIBUTE_PURE
812 _GL_ARG_NONNULL ((1, 2))); 972 _GL_ARG_NONNULL ((1, 2)));
813# endif 973# endif
@@ -834,7 +994,6 @@ _GL_CXXALIASWARN (strpbrk);
834 Even in this simple case, it does not work with multibyte strings if the 994 Even in this simple case, it does not work with multibyte strings if the
835 locale encoding is GB18030 and one of the characters to be searched is a 995 locale encoding is GB18030 and one of the characters to be searched is a
836 digit. */ 996 digit. */
837# undef strpbrk
838_GL_WARN_ON_USE_CXX (strpbrk, 997_GL_WARN_ON_USE_CXX (strpbrk,
839 const char *, char *, (const char *, const char *), 998 const char *, char *, (const char *, const char *),
840 "strpbrk cannot work correctly on character strings " 999 "strpbrk cannot work correctly on character strings "
@@ -854,7 +1013,6 @@ _GL_WARN_ON_USE_CXX (strpbrk,
854#if defined GNULIB_POSIXCHECK 1013#if defined GNULIB_POSIXCHECK
855/* strspn() assumes the second argument is a list of single-byte characters. 1014/* strspn() assumes the second argument is a list of single-byte characters.
856 Even in this simple case, it cannot work with multibyte strings. */ 1015 Even in this simple case, it cannot work with multibyte strings. */
857# undef strspn
858/* Assume strspn is always declared. */ 1016/* Assume strspn is always declared. */
859_GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings " 1017_GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
860 "in multibyte locales - " 1018 "in multibyte locales - "
@@ -864,7 +1022,6 @@ _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
864#if defined GNULIB_POSIXCHECK 1022#if defined GNULIB_POSIXCHECK
865/* strrchr() does not work with multibyte strings if the locale encoding is 1023/* strrchr() does not work with multibyte strings if the locale encoding is
866 GB18030 and the character to be searched is a digit. */ 1024 GB18030 and the character to be searched is a digit. */
867# undef strrchr
868/* Assume strrchr is always declared. */ 1025/* Assume strrchr is always declared. */
869_GL_WARN_ON_USE_CXX (strrchr, 1026_GL_WARN_ON_USE_CXX (strrchr,
870 const char *, char *, (const char *, int), 1027 const char *, char *, (const char *, int),
@@ -892,20 +1049,18 @@ _GL_WARN_ON_USE_CXX (strrchr,
892#if @GNULIB_STRSEP@ 1049#if @GNULIB_STRSEP@
893# if ! @HAVE_STRSEP@ 1050# if ! @HAVE_STRSEP@
894_GL_FUNCDECL_SYS (strsep, char *, 1051_GL_FUNCDECL_SYS (strsep, char *,
895 (char **restrict __stringp, char const *restrict __delim) 1052 (char **restrict __stringp, char const *restrict __delim),
896 _GL_ARG_NONNULL ((1, 2))); 1053 _GL_ARG_NONNULL ((1, 2)));
897# endif 1054# endif
898_GL_CXXALIAS_SYS (strsep, char *, 1055_GL_CXXALIAS_SYS (strsep, char *,
899 (char **restrict __stringp, char const *restrict __delim)); 1056 (char **restrict __stringp, char const *restrict __delim));
900_GL_CXXALIASWARN (strsep); 1057_GL_CXXALIASWARN (strsep);
901# if defined GNULIB_POSIXCHECK 1058# if defined GNULIB_POSIXCHECK
902# undef strsep
903_GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings " 1059_GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings "
904 "in multibyte locales - " 1060 "in multibyte locales - "
905 "use mbssep if you care about internationalization"); 1061 "use mbssep if you care about internationalization");
906# endif 1062# endif
907#elif defined GNULIB_POSIXCHECK 1063#elif defined GNULIB_POSIXCHECK
908# undef strsep
909# if HAVE_RAW_DECL_STRSEP 1064# if HAVE_RAW_DECL_STRSEP
910_GL_WARN_ON_USE (strsep, "strsep is unportable - " 1065_GL_WARN_ON_USE (strsep, "strsep is unportable - "
911 "use gnulib module strsep for portability"); 1066 "use gnulib module strsep for portability");
@@ -917,7 +1072,7 @@ _GL_WARN_ON_USE (strsep, "strsep is unportable - "
917# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1072# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
918# define strstr rpl_strstr 1073# define strstr rpl_strstr
919# endif 1074# endif
920_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle) 1075_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle),
921 _GL_ATTRIBUTE_PURE 1076 _GL_ATTRIBUTE_PURE
922 _GL_ARG_NONNULL ((1, 2))); 1077 _GL_ARG_NONNULL ((1, 2)));
923_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle)); 1078_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle));
@@ -948,11 +1103,13 @@ _GL_CXXALIASWARN (strstr);
948 as a sequence of bytes, not of characters. */ 1103 as a sequence of bytes, not of characters. */
949# undef strstr 1104# undef strstr
950/* Assume strstr is always declared. */ 1105/* Assume strstr is always declared. */
951_GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot " 1106_GL_WARN_ON_USE_CXX (strstr,
952 "work correctly on character strings in most " 1107 const char *, char *, (const char *, const char *),
953 "multibyte locales - " 1108 "strstr is quadratic on many systems, and cannot "
954 "use mbsstr if you care about internationalization, " 1109 "work correctly on character strings in most "
955 "or use strstr if you care about speed"); 1110 "multibyte locales - "
1111 "use mbsstr if you care about internationalization, "
1112 "or use strstr if you care about speed");
956#endif 1113#endif
957 1114
958/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive 1115/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
@@ -963,7 +1120,7 @@ _GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot "
963# define strcasestr rpl_strcasestr 1120# define strcasestr rpl_strcasestr
964# endif 1121# endif
965_GL_FUNCDECL_RPL (strcasestr, char *, 1122_GL_FUNCDECL_RPL (strcasestr, char *,
966 (const char *haystack, const char *needle) 1123 (const char *haystack, const char *needle),
967 _GL_ATTRIBUTE_PURE 1124 _GL_ATTRIBUTE_PURE
968 _GL_ARG_NONNULL ((1, 2))); 1125 _GL_ARG_NONNULL ((1, 2)));
969_GL_CXXALIAS_RPL (strcasestr, char *, 1126_GL_CXXALIAS_RPL (strcasestr, char *,
@@ -971,7 +1128,7 @@ _GL_CXXALIAS_RPL (strcasestr, char *,
971# else 1128# else
972# if ! @HAVE_STRCASESTR@ 1129# if ! @HAVE_STRCASESTR@
973_GL_FUNCDECL_SYS (strcasestr, char *, 1130_GL_FUNCDECL_SYS (strcasestr, char *,
974 (const char *haystack, const char *needle) 1131 (const char *haystack, const char *needle),
975 _GL_ATTRIBUTE_PURE 1132 _GL_ATTRIBUTE_PURE
976 _GL_ARG_NONNULL ((1, 2))); 1133 _GL_ARG_NONNULL ((1, 2)));
977# endif 1134# endif
@@ -998,7 +1155,6 @@ _GL_CXXALIASWARN (strcasestr);
998/* strcasestr() does not work with multibyte strings: 1155/* strcasestr() does not work with multibyte strings:
999 It is a glibc extension, and glibc implements it only for unibyte 1156 It is a glibc extension, and glibc implements it only for unibyte
1000 locales. */ 1157 locales. */
1001# undef strcasestr
1002# if HAVE_RAW_DECL_STRCASESTR 1158# if HAVE_RAW_DECL_STRCASESTR
1003_GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character " 1159_GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
1004 "strings in multibyte locales - " 1160 "strings in multibyte locales - "
@@ -1038,19 +1194,19 @@ _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
1038# endif 1194# endif
1039_GL_FUNCDECL_RPL (strtok_r, char *, 1195_GL_FUNCDECL_RPL (strtok_r, char *,
1040 (char *restrict s, char const *restrict delim, 1196 (char *restrict s, char const *restrict delim,
1041 char **restrict save_ptr) 1197 char **restrict save_ptr),
1042 _GL_ARG_NONNULL ((2, 3))); 1198 _GL_ARG_NONNULL ((2, 3)));
1043_GL_CXXALIAS_RPL (strtok_r, char *, 1199_GL_CXXALIAS_RPL (strtok_r, char *,
1044 (char *restrict s, char const *restrict delim, 1200 (char *restrict s, char const *restrict delim,
1045 char **restrict save_ptr)); 1201 char **restrict save_ptr));
1046# else 1202# else
1047# if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK 1203# if @UNDEFINE_STRTOK_R@
1048# undef strtok_r 1204# undef strtok_r
1049# endif 1205# endif
1050# if ! @HAVE_DECL_STRTOK_R@ 1206# if ! @HAVE_DECL_STRTOK_R@
1051_GL_FUNCDECL_SYS (strtok_r, char *, 1207_GL_FUNCDECL_SYS (strtok_r, char *,
1052 (char *restrict s, char const *restrict delim, 1208 (char *restrict s, char const *restrict delim,
1053 char **restrict save_ptr) 1209 char **restrict save_ptr),
1054 _GL_ARG_NONNULL ((2, 3))); 1210 _GL_ARG_NONNULL ((2, 3)));
1055# endif 1211# endif
1056_GL_CXXALIAS_SYS (strtok_r, char *, 1212_GL_CXXALIAS_SYS (strtok_r, char *,
@@ -1064,7 +1220,6 @@ _GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character "
1064 "use mbstok_r if you care about internationalization"); 1220 "use mbstok_r if you care about internationalization");
1065# endif 1221# endif
1066#elif defined GNULIB_POSIXCHECK 1222#elif defined GNULIB_POSIXCHECK
1067# undef strtok_r
1068# if HAVE_RAW_DECL_STRTOK_R 1223# if HAVE_RAW_DECL_STRTOK_R
1069_GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - " 1224_GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
1070 "use gnulib module strtok_r for portability"); 1225 "use gnulib module strtok_r for portability");
@@ -1075,22 +1230,38 @@ _GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - "
1075/* The following functions are not specified by POSIX. They are gnulib 1230/* The following functions are not specified by POSIX. They are gnulib
1076 extensions. */ 1231 extensions. */
1077 1232
1233#if @GNULIB_STR_STARTSWITH@
1234/* Returns true if STRING starts with PREFIX.
1235 Returns false otherwise. */
1236_GL_EXTERN_C bool str_startswith (const char *string, const char *prefix)
1237 _GL_ATTRIBUTE_PURE
1238 _GL_ARG_NONNULL ((1, 2));
1239#endif
1240
1241#if @GNULIB_STR_ENDSWITH@
1242/* Returns true if STRING ends with SUFFIX.
1243 Returns false otherwise. */
1244_GL_EXTERN_C bool str_endswith (const char *string, const char *prefix)
1245 _GL_ATTRIBUTE_PURE
1246 _GL_ARG_NONNULL ((1, 2));
1247#endif
1248
1078#if @GNULIB_MBSLEN@ 1249#if @GNULIB_MBSLEN@
1079/* Return the number of multibyte characters in the character string STRING. 1250/* Return the number of multibyte characters in the character string STRING.
1080 This considers multibyte characters, unlike strlen, which counts bytes. */ 1251 This considers multibyte characters, unlike strlen, which counts bytes. */
1081# ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */ 1252# ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */
1082# undef mbslen 1253# undef mbslen
1083# endif 1254# endif
1084# if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */ 1255# if @HAVE_MBSLEN@ /* AIX, MirBSD define mbslen already in libc. */
1085# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1256# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1086# define mbslen rpl_mbslen 1257# define mbslen rpl_mbslen
1087# endif 1258# endif
1088_GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) 1259_GL_FUNCDECL_RPL (mbslen, size_t, (const char *string),
1089 _GL_ATTRIBUTE_PURE 1260 _GL_ATTRIBUTE_PURE
1090 _GL_ARG_NONNULL ((1))); 1261 _GL_ARG_NONNULL ((1)));
1091_GL_CXXALIAS_RPL (mbslen, size_t, (const char *string)); 1262_GL_CXXALIAS_RPL (mbslen, size_t, (const char *string));
1092# else 1263# else
1093_GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) 1264_GL_FUNCDECL_SYS (mbslen, size_t, (const char *string),
1094 _GL_ATTRIBUTE_PURE 1265 _GL_ATTRIBUTE_PURE
1095 _GL_ARG_NONNULL ((1))); 1266 _GL_ARG_NONNULL ((1)));
1096_GL_CXXALIAS_SYS (mbslen, size_t, (const char *string)); 1267_GL_CXXALIAS_SYS (mbslen, size_t, (const char *string));
@@ -1117,12 +1288,12 @@ _GL_EXTERN_C size_t mbsnlen (const char *string, size_t len)
1117# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1288# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1118# define mbschr rpl_mbschr /* avoid collision with HP-UX function */ 1289# define mbschr rpl_mbschr /* avoid collision with HP-UX function */
1119# endif 1290# endif
1120_GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c) 1291_GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c),
1121 _GL_ATTRIBUTE_PURE 1292 _GL_ATTRIBUTE_PURE
1122 _GL_ARG_NONNULL ((1))); 1293 _GL_ARG_NONNULL ((1)));
1123_GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c)); 1294_GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c));
1124# else 1295# else
1125_GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c) 1296_GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c),
1126 _GL_ATTRIBUTE_PURE 1297 _GL_ATTRIBUTE_PURE
1127 _GL_ARG_NONNULL ((1))); 1298 _GL_ARG_NONNULL ((1)));
1128_GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c)); 1299_GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c));
@@ -1139,12 +1310,12 @@ _GL_CXXALIASWARN (mbschr);
1139# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1310# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1140# define mbsrchr rpl_mbsrchr /* avoid collision with system function */ 1311# define mbsrchr rpl_mbsrchr /* avoid collision with system function */
1141# endif 1312# endif
1142_GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c) 1313_GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c),
1143 _GL_ATTRIBUTE_PURE 1314 _GL_ATTRIBUTE_PURE
1144 _GL_ARG_NONNULL ((1))); 1315 _GL_ARG_NONNULL ((1)));
1145_GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c)); 1316_GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c));
1146# else 1317# else
1147_GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c) 1318_GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c),
1148 _GL_ATTRIBUTE_PURE 1319 _GL_ATTRIBUTE_PURE
1149 _GL_ARG_NONNULL ((1))); 1320 _GL_ARG_NONNULL ((1)));
1150_GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c)); 1321_GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c));
@@ -1160,6 +1331,33 @@ _GL_CXXALIASWARN (mbsrchr);
1160_GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle) 1331_GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle)
1161 _GL_ATTRIBUTE_PURE 1332 _GL_ATTRIBUTE_PURE
1162 _GL_ARG_NONNULL ((1, 2)); 1333 _GL_ARG_NONNULL ((1, 2));
1334# ifndef _GL_NO_CONST_GENERICS
1335/* Don't silently convert a 'const char *' to a 'char *'. Programmers want
1336 compiler warnings for 'const' related mistakes. */
1337# ifdef __cplusplus
1338extern "C++" { /* needed for AIX */
1339template <typename T>
1340 T * mbsstr_template (T* haystack, const char *needle);
1341template <>
1342 inline char * mbsstr_template (char *haystack, const char *needle)
1343 { return mbsstr (haystack, needle); }
1344template <>
1345 inline const char * mbsstr_template (const char *haystack, const char *needle)
1346 { return mbsstr (haystack, needle); }
1347}
1348# undef mbsstr
1349# define mbsstr mbsstr_template
1350# elif !defined mbsstr
1351# if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
1352 || defined __ICC || defined __TINYC__ \
1353 || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
1354# define mbsstr(h,n) \
1355 _Generic ((h), \
1356 char const *: (char const *) mbsstr ((h), (n)), \
1357 default : mbsstr ((h), (n)))
1358# endif
1359# endif
1360# endif
1163#endif 1361#endif
1164 1362
1165#if @GNULIB_MBSCASECMP@ 1363#if @GNULIB_MBSCASECMP@
@@ -1201,6 +1399,33 @@ _GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n)
1201_GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix) 1399_GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
1202 _GL_ATTRIBUTE_PURE 1400 _GL_ATTRIBUTE_PURE
1203 _GL_ARG_NONNULL ((1, 2)); 1401 _GL_ARG_NONNULL ((1, 2));
1402# ifndef _GL_NO_CONST_GENERICS
1403/* Don't silently convert a 'const char *' to a 'char *'. Programmers want
1404 compiler warnings for 'const' related mistakes. */
1405# ifdef __cplusplus
1406extern "C++" { /* needed for AIX */
1407template <typename T>
1408 T * mbspcasecmp_template (T* string, const char *prefix);
1409template <>
1410 inline char * mbspcasecmp_template (char *string, const char *prefix)
1411 { return mbspcasecmp (string, prefix); }
1412template <>
1413 inline const char * mbspcasecmp_template (const char *string, const char *prefix)
1414 { return mbspcasecmp (string, prefix); }
1415}
1416# undef mbspcasecmp
1417# define mbspcasecmp mbspcasecmp_template
1418# elif !defined mbspcasecmp
1419# if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
1420 || defined __ICC || defined __TINYC__ \
1421 || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
1422# define mbspcasecmp(s,p) \
1423 _Generic ((s), \
1424 char const *: (char const *) mbspcasecmp ((s), (p)), \
1425 default : mbspcasecmp ((s), (p)))
1426# endif
1427# endif
1428# endif
1204#endif 1429#endif
1205 1430
1206#if @GNULIB_MBSCASESTR@ 1431#if @GNULIB_MBSCASESTR@
@@ -1212,6 +1437,33 @@ _GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix)
1212_GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle) 1437_GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle)
1213 _GL_ATTRIBUTE_PURE 1438 _GL_ATTRIBUTE_PURE
1214 _GL_ARG_NONNULL ((1, 2)); 1439 _GL_ARG_NONNULL ((1, 2));
1440# ifndef _GL_NO_CONST_GENERICS
1441/* Don't silently convert a 'const char *' to a 'char *'. Programmers want
1442 compiler warnings for 'const' related mistakes. */
1443# ifdef __cplusplus
1444extern "C++" { /* needed for AIX */
1445template <typename T>
1446 T * mbscasestr_template (T* haystack, const char *needle);
1447template <>
1448 inline char * mbscasestr_template (char *haystack, const char *needle)
1449 { return mbscasestr (haystack, needle); }
1450template <>
1451 inline const char * mbscasestr_template (const char *haystack, const char *needle)
1452 { return mbscasestr (haystack, needle); }
1453}
1454# undef mbscasestr
1455# define mbscasestr mbscasestr_template
1456# elif !defined mbscasestr
1457# if ((__GNUC__ + (__GNUC_MINOR__ >= 9) > 4) || (__clang_major__ >= 3) \
1458 || defined __ICC || defined __TINYC__ \
1459 || (__STDC_VERSION__ >= 201112L && !(defined __GNUC__ || defined __clang__)))
1460# define mbscasestr(h,n) \
1461 _Generic ((h), \
1462 char const *: (char const *) mbscasestr ((h), (n)), \
1463 default : mbscasestr ((h), (n)))
1464# endif
1465# endif
1466# endif
1215#endif 1467#endif
1216 1468
1217#if @GNULIB_MBSCSPN@ 1469#if @GNULIB_MBSCSPN@
@@ -1234,12 +1486,12 @@ _GL_EXTERN_C size_t mbscspn (const char *string, const char *accept)
1234# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1486# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1235# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ 1487# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
1236# endif 1488# endif
1237_GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept) 1489_GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept),
1238 _GL_ATTRIBUTE_PURE 1490 _GL_ATTRIBUTE_PURE
1239 _GL_ARG_NONNULL ((1, 2))); 1491 _GL_ARG_NONNULL ((1, 2)));
1240_GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept)); 1492_GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept));
1241# else 1493# else
1242_GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept) 1494_GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept),
1243 _GL_ATTRIBUTE_PURE 1495 _GL_ATTRIBUTE_PURE
1244 _GL_ARG_NONNULL ((1, 2))); 1496 _GL_ARG_NONNULL ((1, 2)));
1245_GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept)); 1497_GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept));
@@ -1299,6 +1551,24 @@ _GL_EXTERN_C char * mbstok_r (char *restrict string, const char *delim,
1299 _GL_ARG_NONNULL ((2, 3)); 1551 _GL_ARG_NONNULL ((2, 3));
1300#endif 1552#endif
1301 1553
1554#if @GNULIB_MBS_STARTSWITH@
1555/* Returns true if STRING starts with PREFIX.
1556 Returns false otherwise. */
1557_GL_EXTERN_C bool mbs_startswith (const char *string, const char *prefix)
1558 _GL_ATTRIBUTE_PURE
1559 _GL_ARG_NONNULL ((1, 2));
1560#endif
1561
1562#if @GNULIB_MBS_ENDSWITH@
1563/* Returns true if STRING ends with SUFFIX.
1564 Returns false otherwise.
1565 Unlike str_endswith(), this function works correctly in multibyte locales.
1566 */
1567_GL_EXTERN_C bool mbs_endswith (const char *string, const char *suffix)
1568 _GL_ATTRIBUTE_PURE
1569 _GL_ARG_NONNULL ((1, 2));
1570#endif
1571
1302/* Map any int, typically from errno, into an error message. */ 1572/* Map any int, typically from errno, into an error message. */
1303#if @GNULIB_STRERROR@ 1573#if @GNULIB_STRERROR@
1304# if @REPLACE_STRERROR@ 1574# if @REPLACE_STRERROR@
@@ -1306,7 +1576,7 @@ _GL_EXTERN_C char * mbstok_r (char *restrict string, const char *delim,
1306# undef strerror 1576# undef strerror
1307# define strerror rpl_strerror 1577# define strerror rpl_strerror
1308# endif 1578# endif
1309_GL_FUNCDECL_RPL (strerror, char *, (int)); 1579_GL_FUNCDECL_RPL (strerror, char *, (int), );
1310_GL_CXXALIAS_RPL (strerror, char *, (int)); 1580_GL_CXXALIAS_RPL (strerror, char *, (int));
1311# else 1581# else
1312_GL_CXXALIAS_SYS (strerror, char *, (int)); 1582_GL_CXXALIAS_SYS (strerror, char *, (int));
@@ -1315,7 +1585,6 @@ _GL_CXXALIAS_SYS (strerror, char *, (int));
1315_GL_CXXALIASWARN (strerror); 1585_GL_CXXALIASWARN (strerror);
1316# endif 1586# endif
1317#elif defined GNULIB_POSIXCHECK 1587#elif defined GNULIB_POSIXCHECK
1318# undef strerror
1319/* Assume strerror is always declared. */ 1588/* Assume strerror is always declared. */
1320_GL_WARN_ON_USE (strerror, "strerror is unportable - " 1589_GL_WARN_ON_USE (strerror, "strerror is unportable - "
1321 "use gnulib module strerror to guarantee non-NULL result"); 1590 "use gnulib module strerror to guarantee non-NULL result");
@@ -1329,12 +1598,12 @@ _GL_WARN_ON_USE (strerror, "strerror is unportable - "
1329# undef strerror_r 1598# undef strerror_r
1330# define strerror_r rpl_strerror_r 1599# define strerror_r rpl_strerror_r
1331# endif 1600# endif
1332_GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen) 1601_GL_FUNCDECL_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen),
1333 _GL_ARG_NONNULL ((2))); 1602 _GL_ARG_NONNULL ((2)));
1334_GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen)); 1603_GL_CXXALIAS_RPL (strerror_r, int, (int errnum, char *buf, size_t buflen));
1335# else 1604# else
1336# if !@HAVE_DECL_STRERROR_R@ 1605# if !@HAVE_DECL_STRERROR_R@
1337_GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen) 1606_GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen),
1338 _GL_ARG_NONNULL ((2))); 1607 _GL_ARG_NONNULL ((2)));
1339# endif 1608# endif
1340_GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)); 1609_GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
@@ -1343,13 +1612,49 @@ _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen));
1343_GL_CXXALIASWARN (strerror_r); 1612_GL_CXXALIASWARN (strerror_r);
1344# endif 1613# endif
1345#elif defined GNULIB_POSIXCHECK 1614#elif defined GNULIB_POSIXCHECK
1346# undef strerror_r
1347# if HAVE_RAW_DECL_STRERROR_R 1615# if HAVE_RAW_DECL_STRERROR_R
1348_GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - " 1616_GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
1349 "use gnulib module strerror_r-posix for portability"); 1617 "use gnulib module strerror_r-posix for portability");
1350# endif 1618# endif
1351#endif 1619#endif
1352 1620
1621/* Map any int, typically from errno, into an error message.
1622 With locale_t argument. */
1623#if @GNULIB_STRERROR_L@
1624# if @REPLACE_STRERROR_L@
1625# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1626# undef strerror_l
1627# define strerror_l rpl_strerror_l
1628# endif
1629_GL_FUNCDECL_RPL (strerror_l, char *, (int errnum, locale_t locale),
1630 _GL_ARG_NONNULL ((2)));
1631_GL_CXXALIAS_RPL (strerror_l, char *, (int errnum, locale_t locale));
1632# else
1633# if !@HAVE_STRERROR_L@
1634_GL_FUNCDECL_SYS (strerror_l, char *, (int errnum, locale_t locale),
1635 _GL_ARG_NONNULL ((2)));
1636# endif
1637_GL_CXXALIAS_SYS (strerror_l, char *, (int errnum, locale_t locale));
1638# endif
1639# if __GLIBC__ >= 2
1640_GL_CXXALIASWARN (strerror_l);
1641# endif
1642#elif defined GNULIB_POSIXCHECK
1643# if HAVE_RAW_DECL_STRERROR_L
1644_GL_WARN_ON_USE (strerror_l, "strerror_l is unportable - "
1645 "use gnulib module strerror_l for portability");
1646# endif
1647#endif
1648
1649/* Map any int, typically from errno, into an error message. Multithread-safe,
1650 with locale_t argument.
1651 Not portable! Only provided by gnulib. */
1652#if @GNULIB_STRERROR_L@
1653_GL_FUNCDECL_SYS (strerror_l_r, int,
1654 (int errnum, char *buf, size_t buflen, locale_t locale),
1655 _GL_ARG_NONNULL ((2, 4)));
1656#endif
1657
1353/* Return the name of the system error code ERRNUM. */ 1658/* Return the name of the system error code ERRNUM. */
1354#if @GNULIB_STRERRORNAME_NP@ 1659#if @GNULIB_STRERRORNAME_NP@
1355# if @REPLACE_STRERRORNAME_NP@ 1660# if @REPLACE_STRERRORNAME_NP@
@@ -1357,17 +1662,18 @@ _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
1357# undef strerrorname_np 1662# undef strerrorname_np
1358# define strerrorname_np rpl_strerrorname_np 1663# define strerrorname_np rpl_strerrorname_np
1359# endif 1664# endif
1360_GL_FUNCDECL_RPL (strerrorname_np, const char *, (int errnum)); 1665_GL_FUNCDECL_RPL (strerrorname_np, const char *, (int errnum), );
1361_GL_CXXALIAS_RPL (strerrorname_np, const char *, (int errnum)); 1666_GL_CXXALIAS_RPL (strerrorname_np, const char *, (int errnum));
1362# else 1667# else
1363# if !@HAVE_STRERRORNAME_NP@ 1668# if !@HAVE_STRERRORNAME_NP@
1364_GL_FUNCDECL_SYS (strerrorname_np, const char *, (int errnum)); 1669_GL_FUNCDECL_SYS (strerrorname_np, const char *, (int errnum), );
1365# endif 1670# endif
1366_GL_CXXALIAS_SYS (strerrorname_np, const char *, (int errnum)); 1671_GL_CXXALIAS_SYS (strerrorname_np, const char *, (int errnum));
1367# endif 1672# endif
1673# if __GLIBC__ >= 2
1368_GL_CXXALIASWARN (strerrorname_np); 1674_GL_CXXALIASWARN (strerrorname_np);
1675# endif
1369#elif defined GNULIB_POSIXCHECK 1676#elif defined GNULIB_POSIXCHECK
1370# undef strerrorname_np
1371# if HAVE_RAW_DECL_STRERRORNAME_NP 1677# if HAVE_RAW_DECL_STRERRORNAME_NP
1372_GL_WARN_ON_USE (strerrorname_np, "strerrorname_np is unportable - " 1678_GL_WARN_ON_USE (strerrorname_np, "strerrorname_np is unportable - "
1373 "use gnulib module strerrorname_np for portability"); 1679 "use gnulib module strerrorname_np for portability");
@@ -1377,12 +1683,11 @@ _GL_WARN_ON_USE (strerrorname_np, "strerrorname_np is unportable - "
1377/* Return an abbreviation string for the signal number SIG. */ 1683/* Return an abbreviation string for the signal number SIG. */
1378#if @GNULIB_SIGABBREV_NP@ 1684#if @GNULIB_SIGABBREV_NP@
1379# if ! @HAVE_SIGABBREV_NP@ 1685# if ! @HAVE_SIGABBREV_NP@
1380_GL_FUNCDECL_SYS (sigabbrev_np, const char *, (int sig)); 1686_GL_FUNCDECL_SYS (sigabbrev_np, const char *, (int sig), );
1381# endif 1687# endif
1382_GL_CXXALIAS_SYS (sigabbrev_np, const char *, (int sig)); 1688_GL_CXXALIAS_SYS (sigabbrev_np, const char *, (int sig));
1383_GL_CXXALIASWARN (sigabbrev_np); 1689_GL_CXXALIASWARN (sigabbrev_np);
1384#elif defined GNULIB_POSIXCHECK 1690#elif defined GNULIB_POSIXCHECK
1385# undef sigabbrev_np
1386# if HAVE_RAW_DECL_SIGABBREV_NP 1691# if HAVE_RAW_DECL_SIGABBREV_NP
1387_GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - " 1692_GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - "
1388 "use gnulib module sigabbrev_np for portability"); 1693 "use gnulib module sigabbrev_np for portability");
@@ -1392,12 +1697,11 @@ _GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - "
1392/* Return an English description string for the signal number SIG. */ 1697/* Return an English description string for the signal number SIG. */
1393#if @GNULIB_SIGDESCR_NP@ 1698#if @GNULIB_SIGDESCR_NP@
1394# if ! @HAVE_SIGDESCR_NP@ 1699# if ! @HAVE_SIGDESCR_NP@
1395_GL_FUNCDECL_SYS (sigdescr_np, const char *, (int sig)); 1700_GL_FUNCDECL_SYS (sigdescr_np, const char *, (int sig), );
1396# endif 1701# endif
1397_GL_CXXALIAS_SYS (sigdescr_np, const char *, (int sig)); 1702_GL_CXXALIAS_SYS (sigdescr_np, const char *, (int sig));
1398_GL_CXXALIASWARN (sigdescr_np); 1703_GL_CXXALIASWARN (sigdescr_np);
1399#elif defined GNULIB_POSIXCHECK 1704#elif defined GNULIB_POSIXCHECK
1400# undef sigdescr_np
1401# if HAVE_RAW_DECL_SIGDESCR_NP 1705# if HAVE_RAW_DECL_SIGDESCR_NP
1402_GL_WARN_ON_USE (sigdescr_np, "sigdescr_np is unportable - " 1706_GL_WARN_ON_USE (sigdescr_np, "sigdescr_np is unportable - "
1403 "use gnulib module sigdescr_np for portability"); 1707 "use gnulib module sigdescr_np for portability");
@@ -1409,11 +1713,11 @@ _GL_WARN_ON_USE (sigdescr_np, "sigdescr_np is unportable - "
1409# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1713# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1410# define strsignal rpl_strsignal 1714# define strsignal rpl_strsignal
1411# endif 1715# endif
1412_GL_FUNCDECL_RPL (strsignal, char *, (int __sig)); 1716_GL_FUNCDECL_RPL (strsignal, char *, (int __sig), );
1413_GL_CXXALIAS_RPL (strsignal, char *, (int __sig)); 1717_GL_CXXALIAS_RPL (strsignal, char *, (int __sig));
1414# else 1718# else
1415# if ! @HAVE_DECL_STRSIGNAL@ 1719# if ! @HAVE_DECL_STRSIGNAL@
1416_GL_FUNCDECL_SYS (strsignal, char *, (int __sig)); 1720_GL_FUNCDECL_SYS (strsignal, char *, (int __sig), );
1417# endif 1721# endif
1418/* Need to cast, because on Cygwin 1.5.x systems, the return type is 1722/* Need to cast, because on Cygwin 1.5.x systems, the return type is
1419 'const char *'. */ 1723 'const char *'. */
@@ -1421,7 +1725,6 @@ _GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig));
1421# endif 1725# endif
1422_GL_CXXALIASWARN (strsignal); 1726_GL_CXXALIASWARN (strsignal);
1423#elif defined GNULIB_POSIXCHECK 1727#elif defined GNULIB_POSIXCHECK
1424# undef strsignal
1425# if HAVE_RAW_DECL_STRSIGNAL 1728# if HAVE_RAW_DECL_STRSIGNAL
1426_GL_WARN_ON_USE (strsignal, "strsignal is unportable - " 1729_GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
1427 "use gnulib module strsignal for portability"); 1730 "use gnulib module strsignal for portability");
@@ -1433,13 +1736,13 @@ _GL_WARN_ON_USE (strsignal, "strsignal is unportable - "
1433# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1736# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1434# define strverscmp rpl_strverscmp 1737# define strverscmp rpl_strverscmp
1435# endif 1738# endif
1436_GL_FUNCDECL_RPL (strverscmp, int, (const char *, const char *) 1739_GL_FUNCDECL_RPL (strverscmp, int, (const char *, const char *),
1437 _GL_ATTRIBUTE_PURE 1740 _GL_ATTRIBUTE_PURE
1438 _GL_ARG_NONNULL ((1, 2))); 1741 _GL_ARG_NONNULL ((1, 2)));
1439_GL_CXXALIAS_RPL (strverscmp, int, (const char *, const char *)); 1742_GL_CXXALIAS_RPL (strverscmp, int, (const char *, const char *));
1440# else 1743# else
1441# if !@HAVE_STRVERSCMP@ 1744# if !@HAVE_STRVERSCMP@
1442_GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *) 1745_GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *),
1443 _GL_ATTRIBUTE_PURE 1746 _GL_ATTRIBUTE_PURE
1444 _GL_ARG_NONNULL ((1, 2))); 1747 _GL_ARG_NONNULL ((1, 2)));
1445# endif 1748# endif
@@ -1447,13 +1750,13 @@ _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *));
1447# endif 1750# endif
1448_GL_CXXALIASWARN (strverscmp); 1751_GL_CXXALIASWARN (strverscmp);
1449#elif defined GNULIB_POSIXCHECK 1752#elif defined GNULIB_POSIXCHECK
1450# undef strverscmp
1451# if HAVE_RAW_DECL_STRVERSCMP 1753# if HAVE_RAW_DECL_STRVERSCMP
1452_GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - " 1754_GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1453 "use gnulib module strverscmp for portability"); 1755 "use gnulib module strverscmp for portability");
1454# endif 1756# endif
1455#endif 1757#endif
1456 1758
1759_GL_INLINE_HEADER_END
1457 1760
1458#endif /* _@GUARD_PREFIX@_STRING_H */ 1761#endif /* _@GUARD_PREFIX@_STRING_H */
1459#endif /* _@GUARD_PREFIX@_STRING_H */ 1762#endif /* _@GUARD_PREFIX@_STRING_H */