string.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #ifndef __STRING_H
  2. #define __STRING_H
  3. #include <features.h>
  4. #include <sys/types.h>
  5. #include <stddef.h>
  6. __BEGIN_DECLS
  7. /* Basic string functions */
  8. /* Return the length of S. */
  9. extern size_t strlen __P ((__const char *__s));
  10. /* Append SRC onto DEST. */
  11. extern char *strcat __P ((char *__restrict __dest,
  12. __const char *__restrict __src));
  13. /* Append no more than N characters from SRC onto DEST. */
  14. extern char *strncat __P ((char *__restrict __dest,
  15. __const char *__restrict __src, size_t __n));
  16. /* Copy SRC to DEST. */
  17. extern char *strcpy __P ((char *__restrict __dest,
  18. __const char *__restrict __src));
  19. extern char *stpcpy __P ((char *__restrict __dest,
  20. __const char *__restrict __src));
  21. /* Copy no more than N characters of SRC to DEST. */
  22. extern char *strncpy __P ((char *__restrict __dest,
  23. __const char *__restrict __src, size_t __n));
  24. /* Compare S1 and S2. */
  25. extern int strcmp __P ((__const char *__s1, __const char *__s2));
  26. /* Compare N characters of S1 and S2. */
  27. extern int strncmp __P ((__const char *__s1, __const char *__s2, size_t __n));
  28. /* Find the first occurrence of C in S. */
  29. extern char *strchr __P ((__const char *__s, int __c));
  30. /* Find the last occurrence of C in S. */
  31. extern char *strrchr __P ((__const char *__s, int __c));
  32. /* Duplicate S, returning an identical malloc'd string. */
  33. extern char *strdup __P ((__const char *__s));
  34. /* Basic mem functions */
  35. /* Copy N bytes of SRC to DEST. */
  36. extern __ptr_t memcpy __P ((__ptr_t __restrict __dest,
  37. __const __ptr_t __restrict __src, size_t __n));
  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. extern __ptr_t memccpy __P ((__ptr_t __dest, __const __ptr_t __src,
  42. int __c, size_t __n));
  43. /* Search N bytes of S for C. */
  44. extern __ptr_t memchr __P ((__const __ptr_t __s, int __c, size_t __n));
  45. /* Set N bytes of S to C. */
  46. extern __ptr_t memset __P ((__ptr_t __s, int __c, size_t __n));
  47. /* Compare N bytes of S1 and S2. */
  48. extern int memcmp __P ((__const __ptr_t __s1, __const __ptr_t __s2,
  49. size_t __n));
  50. /* Copy N bytes of SRC to DEST, guaranteeing
  51. correct behavior for overlapping strings. */
  52. extern __ptr_t memmove __P ((__ptr_t __dest, __const __ptr_t __src,
  53. size_t __n));
  54. /* Minimal (very!) locale support */
  55. extern int strcoll __P ((__const char *__s1, __const char *__s2));
  56. extern size_t strxfrm __P ((char *__restrict __dest,
  57. __const char *__restrict __src, size_t __n));
  58. /* BSDisms */
  59. extern char *index __P ((__const char *__s, int __c));
  60. extern char *rindex __P ((__const char *__s, int __c));
  61. /* Return the position of the first bit set in I, or 0 if none are set.
  62. The least-significant bit is position 1, the most-significant 32. */
  63. extern int ffs __P ((int __i)) __attribute__ ((const));
  64. /* Other common BSD functions */
  65. /* Set N bytes of S to 0. */
  66. extern void bzero __P ((__ptr_t __s, size_t __n));
  67. /* Copy N bytes of SRC to DEST (like memmove, but args reversed). */
  68. extern void bcopy __P ((__const __ptr_t __src, __ptr_t __dest, size_t __n));
  69. /* Compare S1 and S2, ignoring case. */
  70. extern int strcasecmp __P ((__const char *__s1, __const char *__s2));
  71. /* Compare no more than N chars of S1 and S2, ignoring case. */
  72. extern int strncasecmp __P ((__const char *__s1, __const char *__s2,
  73. size_t __n));
  74. /* Find the first occurrence in S of any character in ACCEPT. */
  75. extern char *strpbrk __P ((__const char *__s, __const char *__accept));
  76. /* Return the next DELIM-delimited token from *STRINGP,
  77. terminating it with a '\0', and update *STRINGP to point past it. */
  78. extern char *strsep __P ((char **__restrict __stringp,
  79. __const char *__restrict __delim));
  80. /* Find the first occurrence of NEEDLE in HAYSTACK. */
  81. extern char *strstr __P ((__const char *__haystack, __const char *__needle));
  82. extern char *strcasestr __P((__const char *__haystack, __const char *__needle));
  83. /* Divide S into tokens separated by characters in DELIM. */
  84. extern char *strtok __P ((char *__restrict __s,
  85. __const char *__restrict __delim));
  86. /* Divide S into tokens separated by characters in DELIM. Information
  87. passed between calls are stored in SAVE_PTR. */
  88. extern char *__strtok_r __P ((char *__restrict __s,
  89. __const char *__restrict __delim,
  90. char **__restrict __save_ptr));
  91. #if defined __USE_POSIX || defined __USE_MISC
  92. extern char *strtok_r __P ((char *__restrict __s,
  93. __const char *__restrict __delim,
  94. char **__restrict __save_ptr));
  95. #endif
  96. /* Return the length of the initial segment of S which
  97. consists entirely of characters not in REJECT. */
  98. extern size_t strcspn __P ((__const char *__s, __const char *__reject));
  99. /* Return the length of the initial segment of S which
  100. consists entirely of characters in ACCEPT. */
  101. extern size_t strspn __P ((__const char *__s, __const char *__accept));
  102. /* Return a string describing the meaning of the signal number in SIG. */
  103. extern char *strsignal __P ((int __sig));
  104. /* More BSD compatabilty */
  105. extern int bcmp(const void *s1, const void *s2, size_t n);
  106. /* Linux silly hour */
  107. char *strfry __P ((char *));
  108. /* Find the length of STRING, but scan at most MAXLEN characters.
  109. If no '\0' terminator is found in that many characters, return MAXLEN. */
  110. extern size_t strnlen __P ((__const char *__string, size_t __maxlen));
  111. /* Duplicate S, returning an identical alloca'd string. */
  112. # define strdupa(s) \
  113. (__extension__ \
  114. ({ \
  115. __const char *__old = (s); \
  116. size_t __len = strlen (__old) + 1; \
  117. char *__new = __builtin_alloca (__len); \
  118. (char *) memcpy (__new, __old, __len); \
  119. }))
  120. /* Return an alloca'd copy of at most N bytes of string. */
  121. # define strndupa(s, n) \
  122. (__extension__ \
  123. ({ \
  124. __const char *__old = (s); \
  125. size_t __len = strnlen (__old, (n)); \
  126. char *__new = __builtin_alloca (__len + 1); \
  127. __new[__len] = '\0'; \
  128. (char *) memcpy (__new, __old, __len); \
  129. }))
  130. __END_DECLS
  131. #endif