string.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /* Copyright (C) 1991-2017 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. #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
  20. #include <bits/libc-header-start.h>
  21. __BEGIN_DECLS
  22. /* Get size_t and NULL from <stddef.h>. */
  23. #define __need_size_t
  24. #define __need_NULL
  25. #include <stddef.h>
  26. /* Tell the caller that we provide correct C++ prototypes. */
  27. #if defined __cplusplus && __GNUC_PREREQ (4, 4)
  28. # define __CORRECT_ISO_CPP_STRING_H_PROTO
  29. #endif
  30. __BEGIN_NAMESPACE_STD
  31. /* Copy N bytes of SRC to DEST. */
  32. extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
  33. size_t __n) __THROW __nonnull ((1, 2));
  34. /* Copy N bytes of SRC to DEST, guaranteeing
  35. correct behavior for overlapping strings. */
  36. extern void *memmove (void *__dest, const void *__src, size_t __n)
  37. __THROW __nonnull ((1, 2));
  38. __END_NAMESPACE_STD
  39. /* Copy no more than N bytes of SRC to DEST, stopping when C is found.
  40. Return the position in DEST one byte past where C was copied,
  41. or NULL if C was not found in the first N bytes of SRC. */
  42. #if defined __USE_MISC || defined __USE_XOPEN
  43. extern void *memccpy (void *__restrict __dest, const void *__restrict __src,
  44. int __c, size_t __n)
  45. __THROW __nonnull ((1, 2));
  46. #endif /* Misc || X/Open. */
  47. __BEGIN_NAMESPACE_STD
  48. /* Set N bytes of S to C. */
  49. extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
  50. /* Compare N bytes of S1 and S2. */
  51. extern int memcmp (const void *__s1, const void *__s2, size_t __n)
  52. __THROW __attribute_pure__ __nonnull ((1, 2));
  53. /* Search N bytes of S for C. */
  54. #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  55. extern "C++"
  56. {
  57. extern void *memchr (void *__s, int __c, size_t __n)
  58. __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
  59. extern const void *memchr (const void *__s, int __c, size_t __n)
  60. __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
  61. # ifdef __OPTIMIZE__
  62. __extern_always_inline void *
  63. memchr (void *__s, int __c, size_t __n) __THROW
  64. {
  65. return __builtin_memchr (__s, __c, __n);
  66. }
  67. __extern_always_inline const void *
  68. memchr (const void *__s, int __c, size_t __n) __THROW
  69. {
  70. return __builtin_memchr (__s, __c, __n);
  71. }
  72. # endif
  73. }
  74. #else
  75. extern void *memchr (const void *__s, int __c, size_t __n)
  76. __THROW __attribute_pure__ __nonnull ((1));
  77. #endif
  78. __END_NAMESPACE_STD
  79. #ifdef __USE_GNU
  80. /* Search in S for C. This is similar to `memchr' but there is no
  81. length limit. */
  82. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  83. extern "C++" void *rawmemchr (void *__s, int __c)
  84. __THROW __asm ("rawmemchr") __attribute_pure__ __nonnull ((1));
  85. extern "C++" const void *rawmemchr (const void *__s, int __c)
  86. __THROW __asm ("rawmemchr") __attribute_pure__ __nonnull ((1));
  87. # else
  88. extern void *rawmemchr (const void *__s, int __c)
  89. __THROW __attribute_pure__ __nonnull ((1));
  90. # endif
  91. /* Search N bytes of S for the final occurrence of C. */
  92. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  93. extern "C++" void *memrchr (void *__s, int __c, size_t __n)
  94. __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1));
  95. extern "C++" const void *memrchr (const void *__s, int __c, size_t __n)
  96. __THROW __asm ("memrchr") __attribute_pure__ __nonnull ((1));
  97. # else
  98. extern void *memrchr (const void *__s, int __c, size_t __n)
  99. __THROW __attribute_pure__ __nonnull ((1));
  100. # endif
  101. #endif
  102. __BEGIN_NAMESPACE_STD
  103. /* Copy SRC to DEST. */
  104. extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
  105. __THROW __nonnull ((1, 2));
  106. /* Copy no more than N characters of SRC to DEST. */
  107. extern char *strncpy (char *__restrict __dest,
  108. const char *__restrict __src, size_t __n)
  109. __THROW __nonnull ((1, 2));
  110. /* Append SRC onto DEST. */
  111. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  112. __THROW __nonnull ((1, 2));
  113. /* Append no more than N characters from SRC onto DEST. */
  114. extern char *strncat (char *__restrict __dest, const char *__restrict __src,
  115. size_t __n) __THROW __nonnull ((1, 2));
  116. /* Compare S1 and S2. */
  117. extern int strcmp (const char *__s1, const char *__s2)
  118. __THROW __attribute_pure__ __nonnull ((1, 2));
  119. /* Compare N characters of S1 and S2. */
  120. extern int strncmp (const char *__s1, const char *__s2, size_t __n)
  121. __THROW __attribute_pure__ __nonnull ((1, 2));
  122. /* Compare the collated forms of S1 and S2. */
  123. extern int strcoll (const char *__s1, const char *__s2)
  124. __THROW __attribute_pure__ __nonnull ((1, 2));
  125. /* Put a transformation of SRC into no more than N bytes of DEST. */
  126. extern size_t strxfrm (char *__restrict __dest,
  127. const char *__restrict __src, size_t __n)
  128. __THROW __nonnull ((2));
  129. __END_NAMESPACE_STD
  130. #ifdef __USE_XOPEN2K8
  131. # include <xlocale.h>
  132. /* Compare the collated forms of S1 and S2, using sorting rules from L. */
  133. extern int strcoll_l (const char *__s1, const char *__s2, __locale_t __l)
  134. __THROW __attribute_pure__ __nonnull ((1, 2, 3));
  135. /* Put a transformation of SRC into no more than N bytes of DEST,
  136. using sorting rules from L. */
  137. extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n,
  138. __locale_t __l) __THROW __nonnull ((2, 4));
  139. #endif
  140. #if (defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 \
  141. || __GLIBC_USE (LIB_EXT2))
  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 || __GLIBC_USE (LIB_EXT2)
  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. /* As bzero, but the compiler will not delete a call to this
  398. function, even if S is dead after the call. */
  399. extern void explicit_bzero (void *__s, size_t __n) __THROW __nonnull ((1));
  400. /* Compare N bytes of S1 and S2 (same as memcmp). */
  401. extern int bcmp (const void *__s1, const void *__s2, size_t __n)
  402. __THROW __attribute_pure__ __nonnull ((1, 2));
  403. /* Find the first occurrence of C in S (same as strchr). */
  404. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  405. extern "C++"
  406. {
  407. extern char *index (char *__s, int __c)
  408. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  409. extern const char *index (const char *__s, int __c)
  410. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  411. # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRINGS_H_PROTO
  412. __extern_always_inline char *
  413. index (char *__s, int __c) __THROW
  414. {
  415. return __builtin_index (__s, __c);
  416. }
  417. __extern_always_inline const char *
  418. index (const char *__s, int __c) __THROW
  419. {
  420. return __builtin_index (__s, __c);
  421. }
  422. # endif
  423. }
  424. # else
  425. extern char *index (const char *__s, int __c)
  426. __THROW __attribute_pure__ __nonnull ((1));
  427. # endif
  428. /* Find the last occurrence of C in S (same as strrchr). */
  429. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  430. extern "C++"
  431. {
  432. extern char *rindex (char *__s, int __c)
  433. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  434. extern const char *rindex (const char *__s, int __c)
  435. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  436. # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRINGS_H_PROTO
  437. __extern_always_inline char *
  438. rindex (char *__s, int __c) __THROW
  439. {
  440. return __builtin_rindex (__s, __c);
  441. }
  442. __extern_always_inline const char *
  443. rindex (const char *__s, int __c) __THROW
  444. {
  445. return __builtin_rindex (__s, __c);
  446. }
  447. #endif
  448. }
  449. # else
  450. extern char *rindex (const char *__s, int __c)
  451. __THROW __attribute_pure__ __nonnull ((1));
  452. # endif
  453. /* Return the position of the first bit set in I, or 0 if none are set.
  454. The least-significant bit is position 1, the most-significant 32. */
  455. extern int ffs (int __i) __THROW __attribute__ ((__const__));
  456. /* The following two functions are non-standard but necessary for non-32 bit
  457. platforms. */
  458. # ifdef __USE_GNU
  459. extern int ffsl (long int __l) __THROW __attribute__ ((__const__));
  460. __extension__ extern int ffsll (long long int __ll)
  461. __THROW __attribute__ ((__const__));
  462. # endif
  463. /* Compare S1 and S2, ignoring case. */
  464. extern int strcasecmp (const char *__s1, const char *__s2)
  465. __THROW __attribute_pure__ __nonnull ((1, 2));
  466. /* Compare no more than N chars of S1 and S2, ignoring case. */
  467. extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
  468. __THROW __attribute_pure__ __nonnull ((1, 2));
  469. #endif /* Use misc. */
  470. #ifdef __USE_GNU
  471. /* Again versions of a few functions which use the given locale instead
  472. of the global one. */
  473. extern int strcasecmp_l (const char *__s1, const char *__s2,
  474. __locale_t __loc)
  475. __THROW __attribute_pure__ __nonnull ((1, 2, 3));
  476. extern int strncasecmp_l (const char *__s1, const char *__s2,
  477. size_t __n, __locale_t __loc)
  478. __THROW __attribute_pure__ __nonnull ((1, 2, 4));
  479. #endif
  480. #ifdef __USE_MISC
  481. /* Return the next DELIM-delimited token from *STRINGP,
  482. terminating it with a '\0', and update *STRINGP to point past it. */
  483. extern char *strsep (char **__restrict __stringp,
  484. const char *__restrict __delim)
  485. __THROW __nonnull ((1, 2));
  486. #endif
  487. #ifdef __USE_XOPEN2K8
  488. /* Return a string describing the meaning of the signal number in SIG. */
  489. extern char *strsignal (int __sig) __THROW;
  490. /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
  491. extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src)
  492. __THROW __nonnull ((1, 2));
  493. extern char *stpcpy (char *__restrict __dest, const char *__restrict __src)
  494. __THROW __nonnull ((1, 2));
  495. /* Copy no more than N characters of SRC to DEST, returning the address of
  496. the last character written into DEST. */
  497. extern char *__stpncpy (char *__restrict __dest,
  498. const char *__restrict __src, size_t __n)
  499. __THROW __nonnull ((1, 2));
  500. extern char *stpncpy (char *__restrict __dest,
  501. const char *__restrict __src, size_t __n)
  502. __THROW __nonnull ((1, 2));
  503. #endif
  504. #ifdef __USE_GNU
  505. /* Compare S1 and S2 as strings holding name & indices/version numbers. */
  506. extern int strverscmp (const char *__s1, const char *__s2)
  507. __THROW __attribute_pure__ __nonnull ((1, 2));
  508. /* Sautee STRING briskly. */
  509. extern char *strfry (char *__string) __THROW __nonnull ((1));
  510. /* Frobnicate N bytes of S. */
  511. extern void *memfrob (void *__s, size_t __n) __THROW __nonnull ((1));
  512. # ifndef basename
  513. /* Return the file name within directory of FILENAME. We don't
  514. declare the function if the `basename' macro is available (defined
  515. in <libgen.h>) which makes the XPG version of this function
  516. available. */
  517. # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
  518. extern "C++" char *basename (char *__filename)
  519. __THROW __asm ("basename") __nonnull ((1));
  520. extern "C++" const char *basename (const char *__filename)
  521. __THROW __asm ("basename") __nonnull ((1));
  522. # else
  523. extern char *basename (const char *__filename) __THROW __nonnull ((1));
  524. # endif
  525. # endif
  526. #endif
  527. #if __GNUC_PREREQ (3,4)
  528. # if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ \
  529. && !defined __NO_INLINE__ && !defined __cplusplus
  530. /* When using GNU CC we provide some optimized versions of selected
  531. functions from this header. There are two kinds of optimizations:
  532. - machine-dependent optimizations, most probably using inline
  533. assembler code; these might be quite expensive since the code
  534. size can increase significantly.
  535. These optimizations are not used unless the symbol
  536. __USE_STRING_INLINES
  537. is defined before including this header.
  538. - machine-independent optimizations which do not increase the
  539. code size significantly and which optimize mainly situations
  540. where one or more arguments are compile-time constants.
  541. These optimizations are used always when the compiler is
  542. taught to optimize.
  543. One can inhibit all optimizations by defining __NO_STRING_INLINES. */
  544. /* Get the machine-dependent optimizations (if any). */
  545. # include <bits/string.h>
  546. /* These are generic optimizations which do not add too much inline code. */
  547. # include <bits/string2.h>
  548. # endif
  549. # if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
  550. /* Functions with security checks. */
  551. # include <bits/string3.h>
  552. # endif
  553. #endif
  554. #if defined __USE_GNU && defined __OPTIMIZE__ \
  555. && defined __extern_always_inline && __GNUC_PREREQ (3,2)
  556. # if !defined _FORCE_INLINES && !defined _HAVE_STRING_ARCH_mempcpy
  557. #define mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)
  558. #define __mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)
  559. __extern_always_inline void *
  560. __mempcpy_inline (void *__restrict __dest,
  561. const void *__restrict __src, size_t __n)
  562. {
  563. return (char *) memcpy (__dest, __src, __n) + __n;
  564. }
  565. # endif
  566. #endif
  567. __END_DECLS
  568. #endif /* string.h */