strings.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* Copyright (C) 1991-2020 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. <https://www.gnu.org/licenses/>. */
  14. #ifndef _STRINGS_H
  15. #define _STRINGS_H 1
  16. #include <features.h>
  17. #define __need_size_t
  18. #include <stddef.h>
  19. /* Tell the caller that we provide correct C++ prototypes. */
  20. #if defined __cplusplus && __GNUC_PREREQ (4, 4)
  21. # define __CORRECT_ISO_CPP_STRINGS_H_PROTO
  22. #endif
  23. __BEGIN_DECLS
  24. #if defined __USE_MISC || !defined __USE_XOPEN2K8
  25. /* Compare N bytes of S1 and S2 (same as memcmp). */
  26. extern int bcmp (const void *__s1, const void *__s2, size_t __n)
  27. __THROW __attribute_pure__ __nonnull ((1, 2));
  28. /* Copy N bytes of SRC to DEST (like memmove, but args reversed). */
  29. extern void bcopy (const void *__src, void *__dest, size_t __n)
  30. __THROW __nonnull ((1, 2));
  31. /* Set N bytes of S to 0. */
  32. extern void bzero (void *__s, size_t __n) __THROW __nonnull ((1));
  33. /* Find the first occurrence of C in S (same as strchr). */
  34. # ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO
  35. extern "C++"
  36. {
  37. extern char *index (char *__s, int __c)
  38. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  39. extern const char *index (const char *__s, int __c)
  40. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  41. # if defined __OPTIMIZE__
  42. __extern_always_inline char *
  43. index (char *__s, int __c) __THROW
  44. {
  45. return __builtin_index (__s, __c);
  46. }
  47. __extern_always_inline const char *
  48. index (const char *__s, int __c) __THROW
  49. {
  50. return __builtin_index (__s, __c);
  51. }
  52. # endif
  53. }
  54. # else
  55. extern char *index (const char *__s, int __c)
  56. __THROW __attribute_pure__ __nonnull ((1));
  57. # endif
  58. /* Find the last occurrence of C in S (same as strrchr). */
  59. # ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO
  60. extern "C++"
  61. {
  62. extern char *rindex (char *__s, int __c)
  63. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  64. extern const char *rindex (const char *__s, int __c)
  65. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  66. # if defined __OPTIMIZE__
  67. __extern_always_inline char *
  68. rindex (char *__s, int __c) __THROW
  69. {
  70. return __builtin_rindex (__s, __c);
  71. }
  72. __extern_always_inline const char *
  73. rindex (const char *__s, int __c) __THROW
  74. {
  75. return __builtin_rindex (__s, __c);
  76. }
  77. # endif
  78. }
  79. # else
  80. extern char *rindex (const char *__s, int __c)
  81. __THROW __attribute_pure__ __nonnull ((1));
  82. # endif
  83. #endif
  84. #if defined __USE_MISC || !defined __USE_XOPEN2K8 || defined __USE_XOPEN2K8XSI
  85. /* Return the position of the first bit set in I, or 0 if none are set.
  86. The least-significant bit is position 1, the most-significant 32. */
  87. extern int ffs (int __i) __THROW __attribute_const__;
  88. #endif
  89. /* The following two functions are non-standard but necessary for non-32 bit
  90. platforms. */
  91. # ifdef __USE_MISC
  92. extern int ffsl (long int __l) __THROW __attribute_const__;
  93. __extension__ extern int ffsll (long long int __ll)
  94. __THROW __attribute_const__;
  95. # endif
  96. /* Compare S1 and S2, ignoring case. */
  97. extern int strcasecmp (const char *__s1, const char *__s2)
  98. __THROW __attribute_pure__ __nonnull ((1, 2));
  99. /* Compare no more than N chars of S1 and S2, ignoring case. */
  100. extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
  101. __THROW __attribute_pure__ __nonnull ((1, 2));
  102. #ifdef __USE_XOPEN2K8
  103. /* POSIX.1-2008 extended locale interface (see locale.h). */
  104. # include <bits/types/locale_t.h>
  105. /* Compare S1 and S2, ignoring case, using collation rules from LOC. */
  106. extern int strcasecmp_l (const char *__s1, const char *__s2, locale_t __loc)
  107. __THROW __attribute_pure__ __nonnull ((1, 2, 3));
  108. /* Compare no more than N chars of S1 and S2, ignoring case, using
  109. collation rules from LOC. */
  110. extern int strncasecmp_l (const char *__s1, const char *__s2,
  111. size_t __n, locale_t __loc)
  112. __THROW __attribute_pure__ __nonnull ((1, 2, 4));
  113. #endif
  114. __END_DECLS
  115. #if __GNUC_PREREQ (3,4) && __USE_FORTIFY_LEVEL > 0 \
  116. && defined __fortify_function
  117. /* Functions with security checks. */
  118. # if defined __USE_MISC || !defined __USE_XOPEN2K8
  119. # include <bits/strings_fortified.h>
  120. # endif
  121. #endif
  122. #endif /* strings.h */