From 00893e79fc62966067af1a106567db96bd170338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 3 Mar 2024 19:11:32 +0100 Subject: New upstream version 1.2 --- lib/string.in.h | 222 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 192 insertions(+), 30 deletions(-) (limited to 'lib/string.in.h') diff --git a/lib/string.in.h b/lib/string.in.h index e56f6db0..44ec2e7e 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 1995-1996, 2001-2022 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 2001-2024 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -44,6 +44,13 @@ #ifndef _@GUARD_PREFIX@_STRING_H #define _@GUARD_PREFIX@_STRING_H +/* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC, + _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, + HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* NetBSD 5.0 mis-defines NULL. */ #include @@ -59,10 +66,11 @@ # include #endif -/* AIX 7.2 declares ffsl and ffsll in , not in . */ +/* AIX 7.2 and Android 13 declare ffsl and ffsll in , not in + . */ /* But in any case avoid namespace pollution on glibc systems. */ #if ((@GNULIB_FFSL@ || @GNULIB_FFSLL@ || defined GNULIB_POSIXCHECK) \ - && defined _AIX) \ + && (defined _AIX || defined __ANDROID__)) \ && ! defined __GLIBC__ # include #endif @@ -82,7 +90,14 @@ can be freed via 'free'; it can be used only after declaring 'free'. */ /* Applies to: functions. Cannot be used on inline functions. */ #ifndef _GL_ATTRIBUTE_DEALLOC_FREE -# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1) +# if defined __cplusplus && defined __GNUC__ && !defined __clang__ +/* Work around GCC bug */ +# define _GL_ATTRIBUTE_DEALLOC_FREE \ + _GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1) +# else +# define _GL_ATTRIBUTE_DEALLOC_FREE \ + _GL_ATTRIBUTE_DEALLOC (free, 1) +# endif #endif /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly @@ -96,6 +111,28 @@ # endif #endif +/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions. + */ +#ifndef _GL_ATTRIBUTE_NOTHROW +# if defined __cplusplus +# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4 +# if __cplusplus >= 201103L +# define _GL_ATTRIBUTE_NOTHROW noexcept (true) +# else +# define _GL_ATTRIBUTE_NOTHROW throw () +# endif +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# else +# if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__ +# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__)) +# else +# define _GL_ATTRIBUTE_NOTHROW +# endif +# endif +#endif + /* The __attribute__ feature is available in gcc versions 2.5 and later. The attribute __pure__ was added in gcc 2.96. */ #ifndef _GL_ATTRIBUTE_PURE @@ -118,7 +155,11 @@ # if (@REPLACE_FREE@ && !defined free \ && !(defined __cplusplus && defined GNULIB_NAMESPACE)) /* We can't do '#define free rpl_free' here. */ +# if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2) +_GL_EXTERN_C void rpl_free (void *) _GL_ATTRIBUTE_NOTHROW; +# else _GL_EXTERN_C void rpl_free (void *); +# endif # undef _GL_ATTRIBUTE_DEALLOC_FREE # define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1) # else @@ -130,7 +171,7 @@ _GL_EXTERN_C void __cdecl free (void *); # else # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2) -_GL_EXTERN_C void free (void *) throw (); +_GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW; # else _GL_EXTERN_C void free (void *); # endif @@ -145,7 +186,7 @@ _GL_EXTERN_C void __cdecl free (void *); # else # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2) -_GL_EXTERN_C void free (void *) throw (); +_GL_EXTERN_C void free (void *) _GL_ATTRIBUTE_NOTHROW; # else _GL_EXTERN_C void free (void *); # endif @@ -248,9 +289,12 @@ _GL_CXXALIAS_SYS_CAST2 (memchr, # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \ || defined __clang__) -_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n) throw ()); +_GL_CXXALIASWARN1 (memchr, void *, + (void *__s, int __c, size_t __n) + _GL_ATTRIBUTE_NOTHROW); _GL_CXXALIASWARN1 (memchr, void const *, - (void const *__s, int __c, size_t __n) throw ()); + (void const *__s, int __c, size_t __n) + _GL_ATTRIBUTE_NOTHROW); # elif __GLIBC__ >= 2 _GL_CXXALIASWARN (memchr); # endif @@ -300,16 +344,32 @@ _GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - " /* Copy N bytes of SRC to DEST, return pointer to bytes after the last written byte. */ #if @GNULIB_MEMPCPY@ -# if ! @HAVE_MEMPCPY@ +# if @REPLACE_MEMPCPY@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mempcpy +# define mempcpy rpl_mempcpy +# endif +_GL_FUNCDECL_RPL (mempcpy, void *, + (void *restrict __dest, void const *restrict __src, + size_t __n) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (mempcpy, void *, + (void *restrict __dest, void const *restrict __src, + size_t __n)); +# else +# if !@HAVE_MEMPCPY@ _GL_FUNCDECL_SYS (mempcpy, void *, (void *restrict __dest, void const *restrict __src, size_t __n) _GL_ARG_NONNULL ((1, 2))); -# endif +# endif _GL_CXXALIAS_SYS (mempcpy, void *, (void *restrict __dest, void const *restrict __src, size_t __n)); +# endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (mempcpy); +# endif #elif defined GNULIB_POSIXCHECK # undef mempcpy # if HAVE_RAW_DECL_MEMPCPY @@ -334,9 +394,13 @@ _GL_CXXALIAS_SYS_CAST2 (memrchr, # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \ || defined __clang__) -_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t) throw ()); -_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t) throw ()); -# else +_GL_CXXALIASWARN1 (memrchr, void *, + (void *, int, size_t) + _GL_ATTRIBUTE_NOTHROW); +_GL_CXXALIASWARN1 (memrchr, void const *, + (void const *, int, size_t) + _GL_ATTRIBUTE_NOTHROW); +# elif __GLIBC__ >= 2 _GL_CXXALIASWARN (memrchr); # endif #elif defined GNULIB_POSIXCHECK @@ -347,6 +411,33 @@ _GL_WARN_ON_USE (memrchr, "memrchr is unportable - " # endif #endif +/* Overwrite a block of memory. The compiler will not optimize + effects away, even if the block is dead after the call. */ +#if @GNULIB_MEMSET_EXPLICIT@ +# if @REPLACE_MEMSET_EXPLICIT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef memset_explicit +# define memset_explicit rpl_memset_explicit +# endif +_GL_FUNCDECL_RPL (memset_explicit, void *, + (void *__dest, int __c, size_t __n) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (memset_explicit, void *, (void *__dest, int __c, size_t __n)); +# else +# if !@HAVE_MEMSET_EXPLICIT@ +_GL_FUNCDECL_SYS (memset_explicit, void *, + (void *__dest, int __c, size_t __n) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (memset_explicit, void *, (void *__dest, int __c, size_t __n)); +# endif +_GL_CXXALIASWARN (memset_explicit); +#elif defined GNULIB_POSIXCHECK +# undef memset_explicit +# if HAVE_RAW_DECL_MEMSET_EXPLICIT +_GL_WARN_ON_USE (memset_explicit, "memset_explicit is unportable - " + "use gnulib module memset_explicit for portability"); +# endif +#endif + /* Find the first occurrence of C in S. More efficient than memchr(S,C,N), at the expense of undefined behavior if C does not occur within N bytes. */ @@ -365,9 +456,12 @@ _GL_CXXALIAS_SYS_CAST2 (rawmemchr, # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \ || defined __clang__) -_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in) throw ()); +_GL_CXXALIASWARN1 (rawmemchr, void *, + (void *__s, int __c_in) + _GL_ATTRIBUTE_NOTHROW); _GL_CXXALIASWARN1 (rawmemchr, void const *, - (void const *__s, int __c_in) throw ()); + (void const *__s, int __c_in) + _GL_ATTRIBUTE_NOTHROW); # else _GL_CXXALIASWARN (rawmemchr); # endif @@ -381,14 +475,28 @@ _GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - " /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ #if @GNULIB_STPCPY@ -# if ! @HAVE_STPCPY@ +# if @REPLACE_STPCPY@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef stpcpy +# define stpcpy rpl_stpcpy +# endif +_GL_FUNCDECL_RPL (stpcpy, char *, + (char *restrict __dst, char const *restrict __src) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (stpcpy, char *, + (char *restrict __dst, char const *restrict __src)); +# else +# if !@HAVE_STPCPY@ _GL_FUNCDECL_SYS (stpcpy, char *, (char *restrict __dst, char const *restrict __src) _GL_ARG_NONNULL ((1, 2))); -# endif +# endif _GL_CXXALIAS_SYS (stpcpy, char *, (char *restrict __dst, char const *restrict __src)); +# endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (stpcpy); +# endif #elif defined GNULIB_POSIXCHECK # undef stpcpy # if HAVE_RAW_DECL_STPCPY @@ -423,7 +531,9 @@ _GL_CXXALIAS_SYS (stpncpy, char *, (char *restrict __dst, char const *restrict __src, size_t __n)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (stpncpy); +# endif #elif defined GNULIB_POSIXCHECK # undef stpncpy # if HAVE_RAW_DECL_STPNCPY @@ -471,10 +581,13 @@ _GL_CXXALIAS_SYS_CAST2 (strchrnul, # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \ || defined __clang__) -_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in) throw ()); +_GL_CXXALIASWARN1 (strchrnul, char *, + (char *__s, int __c_in) + _GL_ATTRIBUTE_NOTHROW); _GL_CXXALIASWARN1 (strchrnul, char const *, - (char const *__s, int __c_in) throw ()); -# else + (char const *__s, int __c_in) + _GL_ATTRIBUTE_NOTHROW); +# elif __GLIBC__ >= 2 _GL_CXXALIASWARN (strchrnul); # endif #elif defined GNULIB_POSIXCHECK @@ -509,10 +622,18 @@ _GL_CXXALIAS_MDA (strdup, char *, (char const *__s)); # undef strdup # endif # if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# else +_GL_FUNCDECL_SYS (strdup, char *, + (char const *__s) + _GL_ARG_NONNULL ((1)) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# endif # endif _GL_CXXALIAS_SYS (strdup, char *, (char const *__s)); # endif @@ -520,10 +641,18 @@ _GL_CXXALIASWARN (strdup); #else # if __GNUC__ >= 11 && !defined strdup /* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */ +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 _GL_FUNCDECL_SYS (strdup, char *, (char const *__s) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# else +_GL_FUNCDECL_SYS (strdup, char *, + (char const *__s) + _GL_ARG_NONNULL ((1)) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# endif # endif # if defined GNULIB_POSIXCHECK # undef strdup @@ -592,10 +721,18 @@ _GL_FUNCDECL_RPL (strndup, char *, _GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n)); # else # if !@HAVE_DECL_STRNDUP@ || (__GNUC__ >= 11 && !defined strndup) +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 _GL_FUNCDECL_SYS (strndup, char *, (char const *__s, size_t __n) + _GL_ATTRIBUTE_NOTHROW _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# else +_GL_FUNCDECL_SYS (strndup, char *, + (char const *__s, size_t __n) + _GL_ARG_NONNULL ((1)) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# endif # endif _GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n)); # endif @@ -603,10 +740,18 @@ _GL_CXXALIASWARN (strndup); #else # if __GNUC__ >= 11 && !defined strndup /* For -Wmismatched-dealloc: Associate strndup with free or rpl_free. */ +# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2 +_GL_FUNCDECL_SYS (strndup, char *, + (char const *__s, size_t __n) + _GL_ATTRIBUTE_NOTHROW + _GL_ARG_NONNULL ((1)) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# else _GL_FUNCDECL_SYS (strndup, char *, (char const *__s, size_t __n) _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# endif # endif # if defined GNULIB_POSIXCHECK # undef strndup @@ -675,9 +820,12 @@ _GL_CXXALIAS_SYS_CAST2 (strpbrk, # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \ || defined __clang__) -_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept) throw ()); +_GL_CXXALIASWARN1 (strpbrk, char *, + (char *__s, char const *__accept) + _GL_ATTRIBUTE_NOTHROW); _GL_CXXALIASWARN1 (strpbrk, char const *, - (char const *__s, char const *__accept) throw ()); + (char const *__s, char const *__accept) + _GL_ATTRIBUTE_NOTHROW); # elif __GLIBC__ >= 2 _GL_CXXALIASWARN (strpbrk); # endif @@ -785,9 +933,11 @@ _GL_CXXALIAS_SYS_CAST2 (strstr, && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \ || defined __clang__) _GL_CXXALIASWARN1 (strstr, char *, - (char *haystack, const char *needle) throw ()); + (char *haystack, const char *needle) + _GL_ATTRIBUTE_NOTHROW); _GL_CXXALIASWARN1 (strstr, const char *, - (const char *haystack, const char *needle) throw ()); + (const char *haystack, const char *needle) + _GL_ATTRIBUTE_NOTHROW); # elif __GLIBC__ >= 2 _GL_CXXALIASWARN (strstr); # endif @@ -836,10 +986,12 @@ _GL_CXXALIAS_SYS_CAST2 (strcasestr, && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \ || defined __clang__) _GL_CXXALIASWARN1 (strcasestr, char *, - (char *haystack, const char *needle) throw ()); + (char *haystack, const char *needle) + _GL_ATTRIBUTE_NOTHROW); _GL_CXXALIASWARN1 (strcasestr, const char *, - (const char *haystack, const char *needle) throw ()); -# else + (const char *haystack, const char *needle) + _GL_ATTRIBUTE_NOTHROW); +# elif __GLIBC__ >= 2 _GL_CXXALIASWARN (strcasestr); # endif #elif defined GNULIB_POSIXCHECK @@ -1187,7 +1339,7 @@ _GL_FUNCDECL_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen) # endif _GL_CXXALIAS_SYS (strerror_r, int, (int errnum, char *buf, size_t buflen)); # endif -# if @HAVE_DECL_STRERROR_R@ +# if __GLIBC__ >= 2 && @HAVE_DECL_STRERROR_R@ _GL_CXXALIASWARN (strerror_r); # endif #elif defined GNULIB_POSIXCHECK @@ -1277,12 +1429,22 @@ _GL_WARN_ON_USE (strsignal, "strsignal is unportable - " #endif #if @GNULIB_STRVERSCMP@ -# if !@HAVE_STRVERSCMP@ +# if @REPLACE_STRVERSCMP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strverscmp rpl_strverscmp +# endif +_GL_FUNCDECL_RPL (strverscmp, int, (const char *, const char *) + _GL_ATTRIBUTE_PURE + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (strverscmp, int, (const char *, const char *)); +# else +# if !@HAVE_STRVERSCMP@ _GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *) _GL_ATTRIBUTE_PURE _GL_ARG_NONNULL ((1, 2))); -# endif +# endif _GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *)); +# endif _GL_CXXALIASWARN (strverscmp); #elif defined GNULIB_POSIXCHECK # undef strverscmp -- cgit v1.2.3