string.in.h 48 KB

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