string.h 6.3 KB

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