string.in.h 22 KB

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