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