string.in.h 36 KB

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