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