string.h 50 KB

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