string.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /* Copyright (C) 1991-2016 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library 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 GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.21 String handling <string.h>
  16. */
  17. #ifndef _STRING_H
  18. #define _STRING_H 1
  19. #include <features.h>
  20. __BEGIN_DECLS
  21. /* Get size_t and NULL from <stddef.h>. */
  22. #define __need_size_t
  23. #define __need_NULL
  24. #include <stddef.h>
  25. /* Tell the caller that we provide correct C++ prototypes. */
  26. #if defined __cplusplus && __GNUC_PREREQ (4, 4)
  27. # define __CORRECT_ISO_CPP_STRING_H_PROTO
  28. #endif
  29. __BEGIN_NAMESPACE_STD
  30. /* Copy N bytes of SRC to DEST. */
  31. extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
  32. size_t __n) __THROW __nonnull ((1, 2));
  33. /* Copy N bytes of SRC to DEST, guaranteeing
  34. correct behavior for overlapping strings. */
  35. extern void *memmove (void *__dest, const void *__src, size_t __n)
  36. __THROW __nonnull ((1, 2));
  37. __END_NAMESPACE_STD
  38. /* Copy no more than N bytes of SRC to DEST, stopping when C is found.
  39. Return the position in DEST one byte past where C was copied,
  40. or NULL if C was not found in the first N bytes of SRC. */
  41. #if defined __USE_MISC || defined __USE_XOPEN
  42. extern void *memccpy (void *__restrict __dest, const void *__restrict __src,
  43. int __c, size_t __n)
  44. __THROW __nonnull ((1, 2));
  45. #endif /* Misc || X/Open. */
  46. __BEGIN_NAMESPACE_STD
  47. /* Set N bytes of S to C. */
  48. extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
  49. /* Compare N bytes of S1 and S2. */
  50. extern int memcmp (const void *__s1, const void *__s2, size_t __n)
  51. __THROW __attribute_pure__ __nonnull ((1, 2));
  52. /* Search N bytes of S for C. */
  53. #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  54. extern "C++"
  55. {
  56. extern void *memchr (void *__s, int __c, size_t __n)
  57. __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
  58. extern const void *memchr (const void *__s, int __c, size_t __n)
  59. __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
  60. # ifdef __OPTIMIZE__
  61. __extern_always_inline void *
  62. memchr (void *__s, int __c, size_t __n) __THROW
  63. {
  64. return __builtin_memchr (__s, __c, __n);
  65. }
  66. __extern_always_inline const void *
  67. memchr (const void *__s, int __c, size_t __n) __THROW
  68. {
  69. return __builtin_memchr (__s, __c, __n);
  70. }
  71. # endif
  72. }
  73. #else
  74. extern void *memchr (const void *__s, int __c, size_t __n)
  75. __THROW __attribute_pure__ __nonnull ((1));
  76. #endif
  77. __END_NAMESPACE_STD
  78. #ifdef __USE_GNU
  79. /* Search in S for C. This is similar to `memchr' but there is no
  80. length limit. */
  81. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  82. extern "C++" void *rawmemchr (void *__s, int __c)
  83. __THROW __asm ("rawmemchr") __attribute_pure__ __nonnull ((1));
  84. extern "C++" const void *rawmemchr (const void *__s, int __c)
  85. __THROW __asm ("rawmemchr") __attribute_pure__ __nonnull ((1));
  86. # else
  87. extern void *rawmemchr (const void *__s, int __c)
  88. __THROW __attribute_pure__ __nonnull ((1));
  89. # endif
  90. /* Search N bytes of S for the final occurrence of C. */
  91. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  92. extern "C++" void *memrchr (void *__s, int __c, size_t __n)
  93. __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1));
  94. extern "C++" const void *memrchr (const void *__s, int __c, size_t __n)
  95. __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1));
  96. # else
  97. extern void *memrchr (const void *__s, int __c, size_t __n)
  98. __THROW __attribute_pure__ __nonnull ((1));
  99. # endif
  100. #endif
  101. __BEGIN_NAMESPACE_STD
  102. /* Copy SRC to DEST. */
  103. extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
  104. __THROW __nonnull ((1, 2));
  105. /* Copy no more than N characters of SRC to DEST. */
  106. extern char *strncpy (char *__restrict __dest,
  107. const char *__restrict __src, size_t __n)
  108. __THROW __nonnull ((1, 2));
  109. /* Append SRC onto DEST. */
  110. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  111. __THROW __nonnull ((1, 2));
  112. /* Append no more than N characters from SRC onto DEST. */
  113. extern char *strncat (char *__restrict __dest, const char *__restrict __src,
  114. size_t __n) __THROW __nonnull ((1, 2));
  115. /* Compare S1 and S2. */
  116. extern int strcmp (const char *__s1, const char *__s2)
  117. __THROW __attribute_pure__ __nonnull ((1, 2));
  118. /* Compare N characters of S1 and S2. */
  119. extern int strncmp (const char *__s1, const char *__s2, size_t __n)
  120. __THROW __attribute_pure__ __nonnull ((1, 2));
  121. /* Compare the collated forms of S1 and S2. */
  122. extern int strcoll (const char *__s1, const char *__s2)
  123. __THROW __attribute_pure__ __nonnull ((1, 2));
  124. /* Put a transformation of SRC into no more than N bytes of DEST. */
  125. extern size_t strxfrm (char *__restrict __dest,
  126. const char *__restrict __src, size_t __n)
  127. __THROW __nonnull ((2));
  128. __END_NAMESPACE_STD
  129. #ifdef __USE_XOPEN2K8
  130. /* The following functions are equivalent to the both above but they
  131. take the locale they use for the collation as an extra argument.
  132. This is not standardsized but something like will come. */
  133. # include <xlocale.h>
  134. /* Compare the collated forms of S1 and S2 using rules from L. */
  135. extern int strcoll_l (const char *__s1, const char *__s2, __locale_t __l)
  136. __THROW __attribute_pure__ __nonnull ((1, 2, 3));
  137. /* Put a transformation of SRC into no more than N bytes of DEST. */
  138. extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n,
  139. __locale_t __l) __THROW __nonnull ((2, 4));
  140. #endif
  141. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
  142. /* Duplicate S, returning an identical malloc'd string. */
  143. extern char *strdup (const char *__s)
  144. __THROW __attribute_malloc__ __nonnull ((1));
  145. #endif
  146. /* Return a malloc'd copy of at most N bytes of STRING. The
  147. resultant string is terminated even if no null terminator
  148. appears before STRING[N]. */
  149. #if defined __USE_XOPEN2K8
  150. extern char *strndup (const char *__string, size_t __n)
  151. __THROW __attribute_malloc__ __nonnull ((1));
  152. #endif
  153. #if defined __USE_GNU && defined __GNUC__
  154. /* Duplicate S, returning an identical alloca'd string. */
  155. # define strdupa(s) \
  156. (__extension__ \
  157. ({ \
  158. const char *__old = (s); \
  159. size_t __len = strlen (__old) + 1; \
  160. char *__new = (char *) __builtin_alloca (__len); \
  161. (char *) memcpy (__new, __old, __len); \
  162. }))
  163. /* Return an alloca'd copy of at most N bytes of string. */
  164. # define strndupa(s, n) \
  165. (__extension__ \
  166. ({ \
  167. const char *__old = (s); \
  168. size_t __len = strnlen (__old, (n)); \
  169. char *__new = (char *) __builtin_alloca (__len + 1); \
  170. __new[__len] = '\0'; \
  171. (char *) memcpy (__new, __old, __len); \
  172. }))
  173. #endif
  174. __BEGIN_NAMESPACE_STD
  175. /* Find the first occurrence of C in S. */
  176. #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  177. extern "C++"
  178. {
  179. extern char *strchr (char *__s, int __c)
  180. __THROW __asm ("strchr") __attribute_pure__ __nonnull ((1));
  181. extern const char *strchr (const char *__s, int __c)
  182. __THROW __asm ("strchr") __attribute_pure__ __nonnull ((1));
  183. # ifdef __OPTIMIZE__
  184. __extern_always_inline char *
  185. strchr (char *__s, int __c) __THROW
  186. {
  187. return __builtin_strchr (__s, __c);
  188. }
  189. __extern_always_inline const char *
  190. strchr (const char *__s, int __c) __THROW
  191. {
  192. return __builtin_strchr (__s, __c);
  193. }
  194. # endif
  195. }
  196. #else
  197. extern char *strchr (const char *__s, int __c)
  198. __THROW __attribute_pure__ __nonnull ((1));
  199. #endif
  200. /* Find the last occurrence of C in S. */
  201. #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  202. extern "C++"
  203. {
  204. extern char *strrchr (char *__s, int __c)
  205. __THROW __asm ("strrchr") __attribute_pure__ __nonnull ((1));
  206. extern const char *strrchr (const char *__s, int __c)
  207. __THROW __asm ("strrchr") __attribute_pure__ __nonnull ((1));
  208. # ifdef __OPTIMIZE__
  209. __extern_always_inline char *
  210. strrchr (char *__s, int __c) __THROW
  211. {
  212. return __builtin_strrchr (__s, __c);
  213. }
  214. __extern_always_inline const char *
  215. strrchr (const char *__s, int __c) __THROW
  216. {
  217. return __builtin_strrchr (__s, __c);
  218. }
  219. # endif
  220. }
  221. #else
  222. extern char *strrchr (const char *__s, int __c)
  223. __THROW __attribute_pure__ __nonnull ((1));
  224. #endif
  225. __END_NAMESPACE_STD
  226. #ifdef __USE_GNU
  227. /* This function is similar to `strchr'. But it returns a pointer to
  228. the closing NUL byte in case C is not found in S. */
  229. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  230. extern "C++" char *strchrnul (char *__s, int __c)
  231. __THROW __asm ("strchrnul") __attribute_pure__ __nonnull ((1));
  232. extern "C++" const char *strchrnul (const char *__s, int __c)
  233. __THROW __asm ("strchrnul") __attribute_pure__ __nonnull ((1));
  234. # else
  235. extern char *strchrnul (const char *__s, int __c)
  236. __THROW __attribute_pure__ __nonnull ((1));
  237. # endif
  238. #endif
  239. __BEGIN_NAMESPACE_STD
  240. /* Return the length of the initial segment of S which
  241. consists entirely of characters not in REJECT. */
  242. extern size_t strcspn (const char *__s, const char *__reject)
  243. __THROW __attribute_pure__ __nonnull ((1, 2));
  244. /* Return the length of the initial segment of S which
  245. consists entirely of characters in ACCEPT. */
  246. extern size_t strspn (const char *__s, const char *__accept)
  247. __THROW __attribute_pure__ __nonnull ((1, 2));
  248. /* Find the first occurrence in S of any character in ACCEPT. */
  249. #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  250. extern "C++"
  251. {
  252. extern char *strpbrk (char *__s, const char *__accept)
  253. __THROW __asm ("strpbrk") __attribute_pure__ __nonnull ((1, 2));
  254. extern const char *strpbrk (const char *__s, const char *__accept)
  255. __THROW __asm ("strpbrk") __attribute_pure__ __nonnull ((1, 2));
  256. # ifdef __OPTIMIZE__
  257. __extern_always_inline char *
  258. strpbrk (char *__s, const char *__accept) __THROW
  259. {
  260. return __builtin_strpbrk (__s, __accept);
  261. }
  262. __extern_always_inline const char *
  263. strpbrk (const char *__s, const char *__accept) __THROW
  264. {
  265. return __builtin_strpbrk (__s, __accept);
  266. }
  267. # endif
  268. }
  269. #else
  270. extern char *strpbrk (const char *__s, const char *__accept)
  271. __THROW __attribute_pure__ __nonnull ((1, 2));
  272. #endif
  273. /* Find the first occurrence of NEEDLE in HAYSTACK. */
  274. #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  275. extern "C++"
  276. {
  277. extern char *strstr (char *__haystack, const char *__needle)
  278. __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2));
  279. extern const char *strstr (const char *__haystack, const char *__needle)
  280. __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2));
  281. # ifdef __OPTIMIZE__
  282. __extern_always_inline char *
  283. strstr (char *__haystack, const char *__needle) __THROW
  284. {
  285. return __builtin_strstr (__haystack, __needle);
  286. }
  287. __extern_always_inline const char *
  288. strstr (const char *__haystack, const char *__needle) __THROW
  289. {
  290. return __builtin_strstr (__haystack, __needle);
  291. }
  292. # endif
  293. }
  294. #else
  295. extern char *strstr (const char *__haystack, const char *__needle)
  296. __THROW __attribute_pure__ __nonnull ((1, 2));
  297. #endif
  298. /* Divide S into tokens separated by characters in DELIM. */
  299. extern char *strtok (char *__restrict __s, const char *__restrict __delim)
  300. __THROW __nonnull ((2));
  301. __END_NAMESPACE_STD
  302. /* Divide S into tokens separated by characters in DELIM. Information
  303. passed between calls are stored in SAVE_PTR. */
  304. extern char *__strtok_r (char *__restrict __s,
  305. const char *__restrict __delim,
  306. char **__restrict __save_ptr)
  307. __THROW __nonnull ((2, 3));
  308. #ifdef __USE_POSIX
  309. extern char *strtok_r (char *__restrict __s, const char *__restrict __delim,
  310. char **__restrict __save_ptr)
  311. __THROW __nonnull ((2, 3));
  312. #endif
  313. #ifdef __USE_GNU
  314. /* Similar to `strstr' but this function ignores the case of both strings. */
  315. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  316. extern "C++" char *strcasestr (char *__haystack, const char *__needle)
  317. __THROW __asm ("strcasestr") __attribute_pure__ __nonnull ((1, 2));
  318. extern "C++" const char *strcasestr (const char *__haystack,
  319. const char *__needle)
  320. __THROW __asm ("strcasestr") __attribute_pure__ __nonnull ((1, 2));
  321. # else
  322. extern char *strcasestr (const char *__haystack, const char *__needle)
  323. __THROW __attribute_pure__ __nonnull ((1, 2));
  324. # endif
  325. #endif
  326. #ifdef __USE_GNU
  327. /* Find the first occurrence of NEEDLE in HAYSTACK.
  328. NEEDLE is NEEDLELEN bytes long;
  329. HAYSTACK is HAYSTACKLEN bytes long. */
  330. extern void *memmem (const void *__haystack, size_t __haystacklen,
  331. const void *__needle, size_t __needlelen)
  332. __THROW __attribute_pure__ __nonnull ((1, 3));
  333. /* Copy N bytes of SRC to DEST, return pointer to bytes after the
  334. last written byte. */
  335. extern void *__mempcpy (void *__restrict __dest,
  336. const void *__restrict __src, size_t __n)
  337. __THROW __nonnull ((1, 2));
  338. extern void *mempcpy (void *__restrict __dest,
  339. const void *__restrict __src, size_t __n)
  340. __THROW __nonnull ((1, 2));
  341. #endif
  342. __BEGIN_NAMESPACE_STD
  343. /* Return the length of S. */
  344. extern size_t strlen (const char *__s)
  345. __THROW __attribute_pure__ __nonnull ((1));
  346. __END_NAMESPACE_STD
  347. #ifdef __USE_XOPEN2K8
  348. /* Find the length of STRING, but scan at most MAXLEN characters.
  349. If no '\0' terminator is found in that many characters, return MAXLEN. */
  350. extern size_t strnlen (const char *__string, size_t __maxlen)
  351. __THROW __attribute_pure__ __nonnull ((1));
  352. #endif
  353. __BEGIN_NAMESPACE_STD
  354. /* Return a string describing the meaning of the `errno' code in ERRNUM. */
  355. extern char *strerror (int __errnum) __THROW;
  356. __END_NAMESPACE_STD
  357. #ifdef __USE_XOPEN2K
  358. /* Reentrant version of `strerror'.
  359. There are 2 flavors of `strerror_r', GNU which returns the string
  360. and may or may not use the supplied temporary buffer and POSIX one
  361. which fills the string into the buffer.
  362. To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L
  363. without -D_GNU_SOURCE is needed, otherwise the GNU version is
  364. preferred. */
  365. # if defined __USE_XOPEN2K && !defined __USE_GNU
  366. /* Fill BUF with a string describing the meaning of the `errno' code in
  367. ERRNUM. */
  368. # ifdef __REDIRECT_NTH
  369. extern int __REDIRECT_NTH (strerror_r,
  370. (int __errnum, char *__buf, size_t __buflen),
  371. __xpg_strerror_r) __nonnull ((2));
  372. # else
  373. extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen)
  374. __THROW __nonnull ((2));
  375. # define strerror_r __xpg_strerror_r
  376. # endif
  377. # else
  378. /* If a temporary buffer is required, at most BUFLEN bytes of BUF will be
  379. used. */
  380. extern char *strerror_r (int __errnum, char *__buf, size_t __buflen)
  381. __THROW __nonnull ((2)) __wur;
  382. # endif
  383. #endif
  384. #ifdef __USE_XOPEN2K8
  385. /* Translate error number to string according to the locale L. */
  386. extern char *strerror_l (int __errnum, __locale_t __l) __THROW;
  387. #endif
  388. /* We define this function always since `bzero' is sometimes needed when
  389. the namespace rules does not allow this. */
  390. extern void __bzero (void *__s, size_t __n) __THROW __nonnull ((1));
  391. #ifdef __USE_MISC
  392. /* Copy N bytes of SRC to DEST (like memmove, but args reversed). */
  393. extern void bcopy (const void *__src, void *__dest, size_t __n)
  394. __THROW __nonnull ((1, 2));
  395. /* Set N bytes of S to 0. */
  396. extern void bzero (void *__s, size_t __n) __THROW __nonnull ((1));
  397. /* Compare N bytes of S1 and S2 (same as memcmp). */
  398. extern int bcmp (const void *__s1, const void *__s2, size_t __n)
  399. __THROW __attribute_pure__ __nonnull ((1, 2));
  400. /* Find the first occurrence of C in S (same as strchr). */
  401. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  402. extern "C++"
  403. {
  404. extern char *index (char *__s, int __c)
  405. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  406. extern const char *index (const char *__s, int __c)
  407. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  408. # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRINGS_H_PROTO
  409. __extern_always_inline char *
  410. index (char *__s, int __c) __THROW
  411. {
  412. return __builtin_index (__s, __c);
  413. }
  414. __extern_always_inline const char *
  415. index (const char *__s, int __c) __THROW
  416. {
  417. return __builtin_index (__s, __c);
  418. }
  419. # endif
  420. }
  421. # else
  422. extern char *index (const char *__s, int __c)
  423. __THROW __attribute_pure__ __nonnull ((1));
  424. # endif
  425. /* Find the last occurrence of C in S (same as strrchr). */
  426. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  427. extern "C++"
  428. {
  429. extern char *rindex (char *__s, int __c)
  430. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  431. extern const char *rindex (const char *__s, int __c)
  432. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  433. # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRINGS_H_PROTO
  434. __extern_always_inline char *
  435. rindex (char *__s, int __c) __THROW
  436. {
  437. return __builtin_rindex (__s, __c);
  438. }
  439. __extern_always_inline const char *
  440. rindex (const char *__s, int __c) __THROW
  441. {
  442. return __builtin_rindex (__s, __c);
  443. }
  444. #endif
  445. }
  446. # else
  447. extern char *rindex (const char *__s, int __c)
  448. __THROW __attribute_pure__ __nonnull ((1));
  449. # endif
  450. /* Return the position of the first bit set in I, or 0 if none are set.
  451. The least-significant bit is position 1, the most-significant 32. */
  452. extern int ffs (int __i) __THROW __attribute__ ((__const__));
  453. /* The following two functions are non-standard but necessary for non-32 bit
  454. platforms. */
  455. # ifdef __USE_GNU
  456. extern int ffsl (long int __l) __THROW __attribute__ ((__const__));
  457. __extension__ extern int ffsll (long long int __ll)
  458. __THROW __attribute__ ((__const__));
  459. # endif
  460. /* Compare S1 and S2, ignoring case. */
  461. extern int strcasecmp (const char *__s1, const char *__s2)
  462. __THROW __attribute_pure__ __nonnull ((1, 2));
  463. /* Compare no more than N chars of S1 and S2, ignoring case. */
  464. extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
  465. __THROW __attribute_pure__ __nonnull ((1, 2));
  466. #endif /* Use misc. */
  467. #ifdef __USE_GNU
  468. /* Again versions of a few functions which use the given locale instead
  469. of the global one. */
  470. extern int strcasecmp_l (const char *__s1, const char *__s2,
  471. __locale_t __loc)
  472. __THROW __attribute_pure__ __nonnull ((1, 2, 3));
  473. extern int strncasecmp_l (const char *__s1, const char *__s2,
  474. size_t __n, __locale_t __loc)
  475. __THROW __attribute_pure__ __nonnull ((1, 2, 4));
  476. #endif
  477. #ifdef __USE_MISC
  478. /* Return the next DELIM-delimited token from *STRINGP,
  479. terminating it with a '\0', and update *STRINGP to point past it. */
  480. extern char *strsep (char **__restrict __stringp,
  481. const char *__restrict __delim)
  482. __THROW __nonnull ((1, 2));
  483. #endif
  484. #ifdef __USE_XOPEN2K8
  485. /* Return a string describing the meaning of the signal number in SIG. */
  486. extern char *strsignal (int __sig) __THROW;
  487. /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
  488. extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src)
  489. __THROW __nonnull ((1, 2));
  490. extern char *stpcpy (char *__restrict __dest, const char *__restrict __src)
  491. __THROW __nonnull ((1, 2));
  492. /* Copy no more than N characters of SRC to DEST, returning the address of
  493. the last character written into DEST. */
  494. extern char *__stpncpy (char *__restrict __dest,
  495. const char *__restrict __src, size_t __n)
  496. __THROW __nonnull ((1, 2));
  497. extern char *stpncpy (char *__restrict __dest,
  498. const char *__restrict __src, size_t __n)
  499. __THROW __nonnull ((1, 2));
  500. #endif
  501. #ifdef __USE_GNU
  502. /* Compare S1 and S2 as strings holding name & indices/version numbers. */
  503. extern int strverscmp (const char *__s1, const char *__s2)
  504. __THROW __attribute_pure__ __nonnull ((1, 2));
  505. /* Sautee STRING briskly. */
  506. extern char *strfry (char *__string) __THROW __nonnull ((1));
  507. /* Frobnicate N bytes of S. */
  508. extern void *memfrob (void *__s, size_t __n) __THROW __nonnull ((1));
  509. # ifndef basename
  510. /* Return the file name within directory of FILENAME. We don't
  511. declare the function if the `basename' macro is available (defined
  512. in <libgen.h>) which makes the XPG version of this function
  513. available. */
  514. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  515. extern "C++" char *basename (char *__filename)
  516. __THROW __asm ("basename") __nonnull ((1));
  517. extern "C++" const char *basename (const char *__filename)
  518. __THROW __asm ("basename") __nonnull ((1));
  519. # else
  520. extern char *basename (const char *__filename) __THROW __nonnull ((1));
  521. # endif
  522. # endif
  523. #endif
  524. #if defined __GNUC__ && __GNUC__ >= 2
  525. # if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ \
  526. && !defined __NO_INLINE__ && !defined __cplusplus
  527. /* When using GNU CC we provide some optimized versions of selected
  528. functions from this header. There are two kinds of optimizations:
  529. - machine-dependent optimizations, most probably using inline
  530. assembler code; these might be quite expensive since the code
  531. size can increase significantly.
  532. These optimizations are not used unless the symbol
  533. __USE_STRING_INLINES
  534. is defined before including this header.
  535. - machine-independent optimizations which do not increase the
  536. code size significantly and which optimize mainly situations
  537. where one or more arguments are compile-time constants.
  538. These optimizations are used always when the compiler is
  539. taught to optimize.
  540. One can inhibit all optimizations by defining __NO_STRING_INLINES. */
  541. /* Get the machine-dependent optimizations (if any). */
  542. # include <bits/string.h>
  543. /* These are generic optimizations which do not add too much inline code. */
  544. # include <bits/string2.h>
  545. # endif
  546. # if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
  547. /* Functions with security checks. */
  548. # include <bits/string3.h>
  549. # endif
  550. #endif
  551. #if defined __USE_GNU && defined __OPTIMIZE__ \
  552. && defined __extern_always_inline && __GNUC_PREREQ (3,2)
  553. # if !defined _FORCE_INLINES && !defined _HAVE_STRING_ARCH_mempcpy
  554. #undef mempcpy
  555. #undef __mempcpy
  556. #define mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)
  557. #define __mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)
  558. __extern_always_inline void *
  559. __mempcpy_inline (void *__restrict __dest,
  560. const void *__restrict __src, size_t __n)
  561. {
  562. return (char *) memcpy (__dest, __src, __n) + __n;
  563. }
  564. # endif
  565. #endif
  566. __END_DECLS
  567. #endif /* string.h */