string.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #ifndef _STRING_H
  2. #ifndef _ISOMAC
  3. /* Some of these are defined as macros in the real string.h, so we must
  4. prototype them before including it. */
  5. #include <sys/types.h>
  6. #include <locale.h>
  7. extern void *__memccpy (void *__dest, const void *__src,
  8. int __c, size_t __n);
  9. extern size_t __strnlen (const char *__string, size_t __maxlen)
  10. __attribute_pure__;
  11. extern char *__strsep (char **__stringp, const char *__delim);
  12. libc_hidden_proto (__strsep)
  13. extern int __strverscmp (const char *__s1, const char *__s2)
  14. __attribute_pure__;
  15. extern int __strncasecmp (const char *__s1, const char *__s2,
  16. size_t __n)
  17. __attribute_pure__;
  18. extern int __strcasecmp (const char *__s1, const char *__s2)
  19. __attribute_pure__;
  20. extern char *__strcasestr (const char *__haystack, const char *__needle)
  21. __attribute_pure__;
  22. extern char *__strdup (const char *__string)
  23. __attribute_malloc__;
  24. extern char *__strndup (const char *__string, size_t __n)
  25. __attribute_malloc__;
  26. extern void *__rawmemchr (const void *__s, int __c)
  27. __attribute_pure__;
  28. extern char *__strchrnul (const char *__s, int __c)
  29. __attribute_pure__;
  30. extern void *__memrchr (const void *__s, int __c, size_t __n)
  31. __attribute_pure__;
  32. extern void *__memchr (const void *__s, int __c, size_t __n)
  33. __attribute_pure__;
  34. extern void __bzero (void *__s, size_t __n) __THROW __nonnull ((1));
  35. extern int __ffs (int __i) __attribute__ ((const));
  36. extern char *__strerror_r (int __errnum, char *__buf, size_t __buflen);
  37. extern char *__strerror_l (int __errnum, locale_t __loc);
  38. extern const char *__sigdescr_np (int __errnum);
  39. libc_hidden_proto (__sigdescr_np)
  40. #endif
  41. #include <string/string.h>
  42. #ifndef _ISOMAC
  43. extern __typeof (strcoll_l) __strcoll_l;
  44. extern __typeof (strxfrm_l) __strxfrm_l;
  45. extern __typeof (strcasecmp_l) __strcasecmp_l;
  46. extern __typeof (strncasecmp_l) __strncasecmp_l;
  47. /* Alternative version which doesn't pollute glibc's namespace. */
  48. #if IS_IN (libc)
  49. # undef strndupa
  50. # define strndupa(s, n) \
  51. (__extension__ \
  52. ({ \
  53. const char *__old = (s); \
  54. size_t __len = __strnlen (__old, (n)); \
  55. char *__new = (char *) __builtin_alloca (__len + 1); \
  56. __new[__len] = '\0'; \
  57. (char *) memcpy (__new, __old, __len); \
  58. }))
  59. #endif
  60. libc_hidden_proto (__mempcpy)
  61. #ifndef __NO_STRING_INLINES
  62. # define __mempcpy(dest, src, n) __builtin_mempcpy (dest, src, n)
  63. #endif
  64. libc_hidden_proto (__stpcpy)
  65. #ifndef __NO_STRING_INLINES
  66. # define __stpcpy(dest, src) __builtin_stpcpy (dest, src)
  67. #endif
  68. libc_hidden_proto (__stpncpy)
  69. extern __typeof (strlcpy) __strlcpy;
  70. libc_hidden_proto (__strlcpy)
  71. extern __typeof (strlcat) __strlcat;
  72. libc_hidden_proto (__strlcat)
  73. libc_hidden_proto (__rawmemchr)
  74. libc_hidden_proto (__strcasecmp)
  75. libc_hidden_proto (__strcasecmp_l)
  76. libc_hidden_proto (__strncasecmp_l)
  77. libc_hidden_proto (__strchrnul)
  78. extern __typeof (strncat) __strncat;
  79. libc_hidden_proto (__strncat)
  80. libc_hidden_proto (__strdup)
  81. libc_hidden_proto (__strndup)
  82. libc_hidden_proto (__strerror_r)
  83. libc_hidden_proto (__strverscmp)
  84. libc_hidden_proto (basename)
  85. extern char *__basename (const char *__filename) __THROW __nonnull ((1));
  86. libc_hidden_proto (__basename)
  87. libc_hidden_proto (strcoll)
  88. libc_hidden_proto (__strcoll_l)
  89. libc_hidden_proto (__strxfrm_l)
  90. libc_hidden_proto (__strtok_r)
  91. extern char *__strsep_g (char **__stringp, const char *__delim);
  92. libc_hidden_proto (__strsep_g)
  93. libc_hidden_proto (strnlen)
  94. libc_hidden_proto (__strnlen)
  95. libc_hidden_proto (__memcmpeq)
  96. libc_hidden_proto (memmem)
  97. extern __typeof (memmem) __memmem;
  98. libc_hidden_proto (__memmem)
  99. libc_hidden_proto (__ffs)
  100. libc_hidden_proto (__strerror_l)
  101. libc_hidden_proto (__memrchr)
  102. #if IS_IN (libc)
  103. /* Avoid hidden reference to IFUNC symbol __explicit_bzero_chk. */
  104. void __explicit_bzero_chk_internal (void *, size_t, size_t)
  105. __THROW __nonnull ((1)) attribute_hidden;
  106. # define explicit_bzero(buf, len) \
  107. __explicit_bzero_chk_internal (buf, len, __glibc_objsize0 (buf))
  108. /* Avoid hidden reference to IFUNC symbol __memset_explicit_chk. */
  109. void *__memset_explicit_chk_internal (void *, int, size_t, size_t)
  110. __THROW __nonnull ((1)) attribute_hidden;
  111. # define memset_explicit(buf, c, len) \
  112. __memset_explicit_chk_internal (buf, c, len, __glibc_objsize0 (buf))
  113. #elif !IS_IN (nonlib)
  114. void __explicit_bzero_chk (void *, size_t, size_t) __THROW __nonnull ((1));
  115. # define explicit_bzero(buf, len) __explicit_bzero_chk (buf, len, \
  116. __glibc_objsize0 (buf))
  117. void *__memset_explicit_chk (void *, int, size_t, size_t)
  118. __THROW __nonnull ((1));
  119. # define memset_explicit(buf, c, len) \
  120. __memset_explicit_chk (buf, c, len, __glibc_objsize0 (buf))
  121. #endif
  122. libc_hidden_builtin_proto (memchr)
  123. libc_hidden_builtin_proto (memcpy)
  124. libc_hidden_builtin_proto (mempcpy)
  125. libc_hidden_builtin_proto (memcmp)
  126. libc_hidden_builtin_proto (memmove)
  127. libc_hidden_builtin_proto (memset)
  128. libc_hidden_builtin_proto (strcat)
  129. libc_hidden_builtin_proto (strchr)
  130. libc_hidden_builtin_proto (strcmp)
  131. libc_hidden_builtin_proto (strcpy)
  132. libc_hidden_builtin_proto (strcspn)
  133. libc_hidden_builtin_proto (strlen)
  134. libc_hidden_builtin_proto (strncmp)
  135. libc_hidden_builtin_proto (strncpy)
  136. libc_hidden_builtin_proto (strpbrk)
  137. libc_hidden_builtin_proto (stpcpy)
  138. libc_hidden_builtin_proto (strrchr)
  139. libc_hidden_builtin_proto (strspn)
  140. libc_hidden_builtin_proto (strstr)
  141. libc_hidden_builtin_proto (ffs)
  142. #if IS_IN (rtld)
  143. extern __typeof (__stpcpy) __stpcpy attribute_hidden;
  144. extern __typeof (__strdup) __strdup attribute_hidden;
  145. extern __typeof (__strerror_r) __strerror_r attribute_hidden;
  146. extern __typeof (__strsep_g) __strsep_g attribute_hidden;
  147. extern __typeof (memchr) memchr attribute_hidden;
  148. extern __typeof (memcmp) memcmp attribute_hidden;
  149. extern __typeof (memcpy) memcpy attribute_hidden;
  150. extern __typeof (memmove) memmove attribute_hidden;
  151. extern __typeof (memset) memset attribute_hidden;
  152. extern __typeof (rawmemchr) rawmemchr attribute_hidden;
  153. extern __typeof (stpcpy) stpcpy attribute_hidden;
  154. extern __typeof (strchr) strchr attribute_hidden;
  155. extern __typeof (strcmp) strcmp attribute_hidden;
  156. extern __typeof (strlen) strlen attribute_hidden;
  157. extern __typeof (strnlen) strnlen attribute_hidden;
  158. extern __typeof (strsep) strsep attribute_hidden;
  159. #endif
  160. #if (IS_IN (libc) || IS_IN (libpthread)) && !defined SHARED \
  161. && !defined NO_MEMPCPY_STPCPY_REDIRECT
  162. /* Redirect calls to __builtin_mempcpy and __builtin_stpcpy to call
  163. __mempcpy and __stpcpy if not inlined. */
  164. # ifdef ATTR_AFTER_FUNC_DECL
  165. extern __typeof (mempcpy) mempcpy __asm__ ("__mempcpy");
  166. extern __typeof (stpcpy) stpcpy __asm__ ("__stpcpy");
  167. # else
  168. __asm__ ("mempcpy = __mempcpy");
  169. __asm__ ("stpcpy = __stpcpy");
  170. # endif
  171. #endif
  172. extern void *__memcpy_chk (void *__restrict __dest,
  173. const void *__restrict __src, size_t __len,
  174. size_t __destlen) __THROW;
  175. extern void *__memmove_chk (void *__dest, const void *__src, size_t __len,
  176. size_t __destlen) __THROW;
  177. extern void *__mempcpy_chk (void *__restrict __dest,
  178. const void *__restrict __src, size_t __len,
  179. size_t __destlen) __THROW;
  180. extern void *__memset_chk (void *__dest, int __ch, size_t __len,
  181. size_t __destlen) __THROW;
  182. extern char *__strcpy_chk (char *__restrict __dest,
  183. const char *__restrict __src,
  184. size_t __destlen) __THROW;
  185. extern char *__stpcpy_chk (char *__restrict __dest,
  186. const char *__restrict __src,
  187. size_t __destlen) __THROW;
  188. extern char *__strncpy_chk (char *__restrict __dest,
  189. const char *__restrict __src,
  190. size_t __len, size_t __destlen) __THROW;
  191. extern char *__strcat_chk (char *__restrict __dest,
  192. const char *__restrict __src,
  193. size_t __destlen) __THROW;
  194. extern char *__strncat_chk (char *__restrict __dest,
  195. const char *__restrict __src,
  196. size_t __len, size_t __destlen) __THROW;
  197. libc_hidden_builtin_proto (__memcpy_chk)
  198. libc_hidden_builtin_proto (__memmove_chk)
  199. libc_hidden_builtin_proto (__mempcpy_chk)
  200. libc_hidden_builtin_proto (__memset_chk)
  201. libc_hidden_builtin_proto (__stpcpy_chk)
  202. libc_hidden_builtin_proto (__strncpy_chk)
  203. libc_hidden_builtin_proto (__strcpy_chk)
  204. #endif
  205. #endif