string.in.h 45 KB

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