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