string.in.h 45 KB

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