string.in.h 21 KB

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