string.in.h 49 KB

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