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