1/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ 2/* A GNU-like <string.h>. 3 4 Copyright (C) 1995-1996, 2001-2007 Free Software Foundation, Inc. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3, or (at your option) 9 any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software Foundation, 18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19 20#ifndef _GL_STRING_H 21 22/* The include_next requires a split double-inclusion guard. */ 23#include_next <string.h> 24 25#ifndef _GL_STRING_H 26#define _GL_STRING_H 27 28 29/* The definition of GL_LINK_WARNING is copied here. */ 30/* GL_LINK_WARNING("literal string") arranges to emit the literal string as 31 a linker warning on most glibc systems. 32 We use a linker warning rather than a preprocessor warning, because 33 #warning cannot be used inside macros. */ 34#ifndef GL_LINK_WARNING 35 /* This works on platforms with GNU ld and ELF object format. 36 Testing __GLIBC__ is sufficient for asserting that GNU ld is in use. 37 Testing __ELF__ guarantees the ELF object format. 38 Testing __GNUC__ is necessary for the compound expression syntax. */ 39# if defined __GLIBC__ && defined __ELF__ && defined __GNUC__ 40# define GL_LINK_WARNING(message) \ 41 GL_LINK_WARNING1 (__FILE__, __LINE__, message) 42# define GL_LINK_WARNING1(file, line, message) \ 43 GL_LINK_WARNING2 (file, line, message) /* macroexpand file and line */ 44# define GL_LINK_WARNING2(file, line, message) \ 45 GL_LINK_WARNING3 (file ":" #line ": warning: " message) 46# define GL_LINK_WARNING3(message) \ 47 ({ static const char warning[sizeof (message)] \ 48 __attribute__ ((__unused__, \ 49 __section__ (".gnu.warning"), \ 50 __aligned__ (1))) \ 51 = message "\n"; \ 52 (void)0; \ 53 }) 54# else 55# define GL_LINK_WARNING(message) ((void) 0) 56# endif 57#endif 58 59 60#ifdef __cplusplus 61extern "C" { 62#endif 63 64 65/* Return the first occurrence of NEEDLE in HAYSTACK. */ 66#if 0 67# if ! 1 68extern void *memmem (void const *__haystack, size_t __haystack_len, 69 void const *__needle, size_t __needle_len); 70# endif 71#elif defined GNULIB_POSIXCHECK 72# undef memmem 73# define memmem(a,al,b,bl) \ 74 (GL_LINK_WARNING ("memmem is unportable - " \ 75 "use gnulib module memmem for portability"), \ 76 memmem (a, al, b, bl)) 77#endif 78 79/* Copy N bytes of SRC to DEST, return pointer to bytes after the 80 last written byte. */ 81#if 1 82# if ! 0 83extern void *mempcpy (void *restrict __dest, void const *restrict __src, 84 size_t __n); 85# endif 86#elif defined GNULIB_POSIXCHECK 87# undef mempcpy 88# define mempcpy(a,b,n) \ 89 (GL_LINK_WARNING ("mempcpy is unportable - " \ 90 "use gnulib module mempcpy for portability"), \ 91 mempcpy (a, b, n)) 92#endif 93 94/* Search backwards through a block for a byte (specified as an int). */ 95#if 1 96# if ! 0 97extern void *memrchr (void const *, int, size_t); 98# endif 99#elif defined GNULIB_POSIXCHECK 100# undef memrchr 101# define memrchr(a,b,c) \ 102 (GL_LINK_WARNING ("memrchr is unportable - " \ 103 "use gnulib module memrchr for portability"), \ 104 memrchr (a, b, c)) 105#endif 106 107/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ 108#if 1 109# if ! 1 110extern char *stpcpy (char *restrict __dst, char const *restrict __src); 111# endif 112#elif defined GNULIB_POSIXCHECK 113# undef stpcpy 114# define stpcpy(a,b) \ 115 (GL_LINK_WARNING ("stpcpy is unportable - " \ 116 "use gnulib module stpcpy for portability"), \ 117 stpcpy (a, b)) 118#endif 119 120/* Copy no more than N bytes of SRC to DST, returning a pointer past the 121 last non-NUL byte written into DST. */ 122#if 0 123# if ! 1 124# define stpncpy gnu_stpncpy 125extern char *stpncpy (char *restrict __dst, char const *restrict __src, 126 size_t __n); 127# endif 128#elif defined GNULIB_POSIXCHECK 129# undef stpncpy 130# define stpncpy(a,b,n) \ 131 (GL_LINK_WARNING ("stpncpy is unportable - " \ 132 "use gnulib module stpncpy for portability"), \ 133 stpncpy (a, b, n)) 134#endif 135 136#if defined GNULIB_POSIXCHECK 137/* strchr() does not work with multibyte strings if the locale encoding is 138 GB18030 and the character to be searched is a digit. */ 139# undef strchr 140# define strchr(s,c) \ 141 (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \ 142 "in some multibyte locales - " \ 143 "use mbschr if you care about internationalization"), \ 144 strchr (s, c)) 145#endif 146 147/* Find the first occurrence of C in S or the final NUL byte. */ 148#if 0 149# if ! 1 150extern char *strchrnul (char const *__s, int __c_in); 151# endif 152#elif defined GNULIB_POSIXCHECK 153# undef strchrnul 154# define strchrnul(a,b) \ 155 (GL_LINK_WARNING ("strchrnul is unportable - " \ 156 "use gnulib module strchrnul for portability"), \ 157 strchrnul (a, b)) 158#endif 159 160/* Duplicate S, returning an identical malloc'd string. */ 161#if 1 162# if ! 1 && ! defined strdup 163extern char *strdup (char const *__s); 164# endif 165#elif defined GNULIB_POSIXCHECK 166# undef strdup 167# define strdup(a) \ 168 (GL_LINK_WARNING ("strdup is unportable - " \ 169 "use gnulib module strdup for portability"), \ 170 strdup (a)) 171#endif 172 173/* Return a newly allocated copy of at most N bytes of STRING. */ 174#if 1 175# if ! 0 176# undef strndup 177# define strndup rpl_strndup 178# endif 179# if ! 0 || ! 0 180extern char *strndup (char const *__string, size_t __n); 181# endif 182#elif defined GNULIB_POSIXCHECK 183# undef strndup 184# define strndup(a,n) \ 185 (GL_LINK_WARNING ("strndup is unportable - " \ 186 "use gnulib module strndup for portability"), \ 187 strndup (a, n)) 188#endif 189 190/* Find the length (number of bytes) of STRING, but scan at most 191 MAXLEN bytes. If no '\0' terminator is found in that many bytes, 192 return MAXLEN. */ 193#if 1 194# if ! 1 195extern size_t strnlen (char const *__string, size_t __maxlen); 196# endif 197#elif defined GNULIB_POSIXCHECK 198# undef strnlen 199# define strnlen(a,n) \ 200 (GL_LINK_WARNING ("strnlen is unportable - " \ 201 "use gnulib module strnlen for portability"), \ 202 strnlen (a, n)) 203#endif 204 205#if defined GNULIB_POSIXCHECK 206/* strcspn() assumes the second argument is a list of single-byte characters. 207 Even in this simple case, it does not work with multibyte strings if the 208 locale encoding is GB18030 and one of the characters to be searched is a 209 digit. */ 210# undef strcspn 211# define strcspn(s,a) \ 212 (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \ 213 "in multibyte locales - " \ 214 "use mbscspn if you care about internationalization"), \ 215 strcspn (s, a)) 216#endif 217 218/* Find the first occurrence in S of any character in ACCEPT. */ 219#if 0 220# if ! 1 221extern char *strpbrk (char const *__s, char const *__accept); 222# endif 223# if defined GNULIB_POSIXCHECK 224/* strpbrk() assumes the second argument is a list of single-byte characters. 225 Even in this simple case, it does not work with multibyte strings if the 226 locale encoding is GB18030 and one of the characters to be searched is a 227 digit. */ 228# undef strpbrk 229# define strpbrk(s,a) \ 230 (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \ 231 "in multibyte locales - " \ 232 "use mbspbrk if you care about internationalization"), \ 233 strpbrk (s, a)) 234# endif 235#elif defined GNULIB_POSIXCHECK 236# undef strpbrk 237# define strpbrk(s,a) \ 238 (GL_LINK_WARNING ("strpbrk is unportable - " \ 239 "use gnulib module strpbrk for portability"), \ 240 strpbrk (s, a)) 241#endif 242 243#if defined GNULIB_POSIXCHECK 244/* strspn() assumes the second argument is a list of single-byte characters. 245 Even in this simple case, it cannot work with multibyte strings. */ 246# undef strspn 247# define strspn(s,a) \ 248 (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \ 249 "in multibyte locales - " \ 250 "use mbsspn if you care about internationalization"), \ 251 strspn (s, a)) 252#endif 253 254#if defined GNULIB_POSIXCHECK 255/* strrchr() does not work with multibyte strings if the locale encoding is 256 GB18030 and the character to be searched is a digit. */ 257# undef strrchr 258# define strrchr(s,c) \ 259 (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \ 260 "in some multibyte locales - " \ 261 "use mbsrchr if you care about internationalization"), \ 262 strrchr (s, c)) 263#endif 264 265/* Search the next delimiter (char listed in DELIM) starting at *STRINGP. 266 If one is found, overwrite it with a NUL, and advance *STRINGP 267 to point to the next char after it. Otherwise, set *STRINGP to NULL. 268 If *STRINGP was already NULL, nothing happens. 269 Return the old value of *STRINGP. 270 271 This is a variant of strtok() that is multithread-safe and supports 272 empty fields. 273 274 Caveat: It modifies the original string. 275 Caveat: These functions cannot be used on constant strings. 276 Caveat: The identity of the delimiting character is lost. 277 Caveat: It doesn't work with multibyte strings unless all of the delimiter 278 characters are ASCII characters < 0x30. 279 280 See also strtok_r(). */ 281#if 0 282# if ! 1 283extern char *strsep (char **restrict __stringp, char const *restrict __delim); 284# endif 285# if defined GNULIB_POSIXCHECK 286# undef strsep 287# define strsep(s,d) \ 288 (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \ 289 "in multibyte locales - " \ 290 "use mbssep if you care about internationalization"), \ 291 strsep (s, d)) 292# endif 293#elif defined GNULIB_POSIXCHECK 294# undef strsep 295# define strsep(s,d) \ 296 (GL_LINK_WARNING ("strsep is unportable - " \ 297 "use gnulib module strsep for portability"), \ 298 strsep (s, d)) 299#endif 300 301#if defined GNULIB_POSIXCHECK 302/* strstr() does not work with multibyte strings if the locale encoding is 303 different from UTF-8: 304 POSIX says that it operates on "strings", and "string" in POSIX is defined 305 as a sequence of bytes, not of characters. */ 306# undef strstr 307# define strstr(a,b) \ 308 (GL_LINK_WARNING ("strstr cannot work correctly on character strings " \ 309 "in most multibyte locales - " \ 310 "use mbsstr if you care about internationalization"), \ 311 strstr (a, b)) 312#endif 313 314/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive 315 comparison. */ 316#if ! 1 317extern char *strcasestr (const char *haystack, const char *needle); 318#endif 319#if defined GNULIB_POSIXCHECK 320/* strcasestr() does not work with multibyte strings: 321 It is a glibc extension, and glibc implements it only for unibyte 322 locales. */ 323# undef strcasestr 324# define strcasestr(a,b) \ 325 (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \ 326 "in multibyte locales - " \ 327 "use mbscasestr if you care about " \ 328 "internationalization, or use c-strcasestr if you want " \ 329 "a locale independent function"), \ 330 strcasestr (a, b)) 331#endif 332 333/* Parse S into tokens separated by characters in DELIM. 334 If S is NULL, the saved pointer in SAVE_PTR is used as 335 the next starting point. For example: 336 char s[] = "-abc-=-def"; 337 char *sp; 338 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" 339 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL 340 x = strtok_r(NULL, "=", &sp); // x = NULL 341 // s = "abc\0-def\0" 342 343 This is a variant of strtok() that is multithread-safe. 344 345 For the POSIX documentation for this function, see: 346 http://www.opengroup.org/susv3xsh/strtok.html 347 348 Caveat: It modifies the original string. 349 Caveat: These functions cannot be used on constant strings. 350 Caveat: The identity of the delimiting character is lost. 351 Caveat: It doesn't work with multibyte strings unless all of the delimiter 352 characters are ASCII characters < 0x30. 353 354 See also strsep(). */ 355#if 0 356# if ! 1 357extern char *strtok_r (char *restrict s, char const *restrict delim, 358 char **restrict save_ptr); 359# endif 360# if defined GNULIB_POSIXCHECK 361# undef strtok_r 362# define strtok_r(s,d,p) \ 363 (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \ 364 "in multibyte locales - " \ 365 "use mbstok_r if you care about internationalization"), \ 366 strtok_r (s, d, p)) 367# endif 368#elif defined GNULIB_POSIXCHECK 369# undef strtok_r 370# define strtok_r(s,d,p) \ 371 (GL_LINK_WARNING ("strtok_r is unportable - " \ 372 "use gnulib module strtok_r for portability"), \ 373 strtok_r (s, d, p)) 374#endif 375 376 377/* The following functions are not specified by POSIX. They are gnulib 378 extensions. */ 379 380#if 0 381/* Return the number of multibyte characters in the character string STRING. 382 This considers multibyte characters, unlike strlen, which counts bytes. */ 383extern size_t mbslen (const char *string); 384#endif 385 386#if 0 387/* Return the number of multibyte characters in the character string starting 388 at STRING and ending at STRING + LEN. */ 389extern size_t mbsnlen (const char *string, size_t len); 390#endif 391 392#if 0 393/* Locate the first single-byte character C in the character string STRING, 394 and return a pointer to it. Return NULL if C is not found in STRING. 395 Unlike strchr(), this function works correctly in multibyte locales with 396 encodings such as GB18030. */ 397# define mbschr rpl_mbschr /* avoid collision with HP-UX function */ 398extern char * mbschr (const char *string, int c); 399#endif 400 401#if 0 402/* Locate the last single-byte character C in the character string STRING, 403 and return a pointer to it. Return NULL if C is not found in STRING. 404 Unlike strrchr(), this function works correctly in multibyte locales with 405 encodings such as GB18030. */ 406# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */ 407extern char * mbsrchr (const char *string, int c); 408#endif 409 410#if 0 411/* Find the first occurrence of the character string NEEDLE in the character 412 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. 413 Unlike strstr(), this function works correctly in multibyte locales with 414 encodings different from UTF-8. */ 415extern char * mbsstr (const char *haystack, const char *needle); 416#endif 417 418#if 0 419/* Compare the character strings S1 and S2, ignoring case, returning less than, 420 equal to or greater than zero if S1 is lexicographically less than, equal to 421 or greater than S2. 422 Note: This function may, in multibyte locales, return 0 for strings of 423 different lengths! 424 Unlike strcasecmp(), this function works correctly in multibyte locales. */ 425extern int mbscasecmp (const char *s1, const char *s2); 426#endif 427 428#if 0 429/* Compare the initial segment of the character string S1 consisting of at most 430 N characters with the initial segment of the character string S2 consisting 431 of at most N characters, ignoring case, returning less than, equal to or 432 greater than zero if the initial segment of S1 is lexicographically less 433 than, equal to or greater than the initial segment of S2. 434 Note: This function may, in multibyte locales, return 0 for initial segments 435 of different lengths! 436 Unlike strncasecmp(), this function works correctly in multibyte locales. 437 But beware that N is not a byte count but a character count! */ 438extern int mbsncasecmp (const char *s1, const char *s2, size_t n); 439#endif 440 441#if 0 442/* Compare the initial segment of the character string STRING consisting of 443 at most mbslen (PREFIX) characters with the character string PREFIX, 444 ignoring case, returning less than, equal to or greater than zero if this 445 initial segment is lexicographically less than, equal to or greater than 446 PREFIX. 447 Note: This function may, in multibyte locales, return 0 if STRING is of 448 smaller length than PREFIX! 449 Unlike strncasecmp(), this function works correctly in multibyte 450 locales. */ 451extern char * mbspcasecmp (const char *string, const char *prefix); 452#endif 453 454#if 0 455/* Find the first occurrence of the character string NEEDLE in the character 456 string HAYSTACK, using case-insensitive comparison. 457 Note: This function may, in multibyte locales, return success even if 458 strlen (haystack) < strlen (needle) ! 459 Unlike strcasestr(), this function works correctly in multibyte locales. */ 460extern char * mbscasestr (const char *haystack, const char *needle); 461#endif 462 463#if 0 464/* Find the first occurrence in the character string STRING of any character 465 in the character string ACCEPT. Return the number of bytes from the 466 beginning of the string to this occurrence, or to the end of the string 467 if none exists. 468 Unlike strcspn(), this function works correctly in multibyte locales. */ 469extern size_t mbscspn (const char *string, const char *accept); 470#endif 471 472#if 0 473/* Find the first occurrence in the character string STRING of any character 474 in the character string ACCEPT. Return the pointer to it, or NULL if none 475 exists. 476 Unlike strpbrk(), this function works correctly in multibyte locales. */ 477# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ 478extern char * mbspbrk (const char *string, const char *accept); 479#endif 480 481#if 0 482/* Find the first occurrence in the character string STRING of any character 483 not in the character string REJECT. Return the number of bytes from the 484 beginning of the string to this occurrence, or to the end of the string 485 if none exists. 486 Unlike strspn(), this function works correctly in multibyte locales. */ 487extern size_t mbsspn (const char *string, const char *reject); 488#endif 489 490#if 0 491/* Search the next delimiter (multibyte character listed in the character 492 string DELIM) starting at the character string *STRINGP. 493 If one is found, overwrite it with a NUL, and advance *STRINGP to point 494 to the next multibyte character after it. Otherwise, set *STRINGP to NULL. 495 If *STRINGP was already NULL, nothing happens. 496 Return the old value of *STRINGP. 497 498 This is a variant of mbstok_r() that supports empty fields. 499 500 Caveat: It modifies the original string. 501 Caveat: These functions cannot be used on constant strings. 502 Caveat: The identity of the delimiting character is lost. 503 504 See also mbstok_r(). */ 505extern char * mbssep (char **stringp, const char *delim); 506#endif 507 508#if 0 509/* Parse the character string STRING into tokens separated by characters in 510 the character string DELIM. 511 If STRING is NULL, the saved pointer in SAVE_PTR is used as 512 the next starting point. For example: 513 char s[] = "-abc-=-def"; 514 char *sp; 515 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" 516 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL 517 x = mbstok_r(NULL, "=", &sp); // x = NULL 518 // s = "abc\0-def\0" 519 520 Caveat: It modifies the original string. 521 Caveat: These functions cannot be used on constant strings. 522 Caveat: The identity of the delimiting character is lost. 523 524 See also mbssep(). */ 525extern char * mbstok_r (char *string, const char *delim, char **save_ptr); 526#endif 527 528/* Map any int, typically from errno, into an error message. */ 529#if 1 530# if 0 531# undef strerror 532# define strerror rpl_strerror 533extern char *strerror (int); 534# endif 535#elif defined GNULIB_POSIXCHECK 536# undef strerror 537# define strerror(e) \ 538 (GL_LINK_WARNING ("strerror is unportable - " \ 539 "use gnulib module strerror to guarantee non-NULL result"), \ 540 strerror (e)) 541#endif 542 543 544#ifdef __cplusplus 545} 546#endif 547 548#endif /* _GL_STRING_H */ 549#endif /* _GL_STRING_H */ 550