strings.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Copyright (C) 1991-2016 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. #ifndef _STRINGS_H
  15. #define _STRINGS_H 1
  16. /* We don't need and should not read this file if <string.h> was already
  17. read. The one exception being that if __USE_MISC isn't defined, then
  18. these aren't defined in string.h, so we need to define them here. */
  19. #if !defined _STRING_H || !defined __USE_MISC
  20. # include <features.h>
  21. # define __need_size_t
  22. # include <stddef.h>
  23. /* Tell the caller that we provide correct C++ prototypes. */
  24. # if defined __cplusplus && __GNUC_PREREQ (4, 4)
  25. # define __CORRECT_ISO_CPP_STRINGS_H_PROTO
  26. # endif
  27. __BEGIN_DECLS
  28. # if defined __USE_MISC || !defined __USE_XOPEN2K8
  29. /* Compare N bytes of S1 and S2 (same as memcmp). */
  30. extern int bcmp (const void *__s1, const void *__s2, size_t __n)
  31. __THROW __attribute_pure__;
  32. /* Copy N bytes of SRC to DEST (like memmove, but args reversed). */
  33. extern void bcopy (const void *__src, void *__dest, size_t __n) __THROW;
  34. /* Set N bytes of S to 0. */
  35. extern void bzero (void *__s, size_t __n) __THROW;
  36. /* Find the first occurrence of C in S (same as strchr). */
  37. # ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO
  38. extern "C++"
  39. {
  40. extern char *index (char *__s, int __c)
  41. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  42. extern const char *index (const char *__s, int __c)
  43. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  44. # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO
  45. __extern_always_inline char *
  46. index (char *__s, int __c) __THROW
  47. {
  48. return __builtin_index (__s, __c);
  49. }
  50. __extern_always_inline const char *
  51. index (const char *__s, int __c) __THROW
  52. {
  53. return __builtin_index (__s, __c);
  54. }
  55. # endif
  56. }
  57. # else
  58. extern char *index (const char *__s, int __c)
  59. __THROW __attribute_pure__ __nonnull ((1));
  60. # endif
  61. /* Find the last occurrence of C in S (same as strrchr). */
  62. # ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO
  63. extern "C++"
  64. {
  65. extern char *rindex (char *__s, int __c)
  66. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  67. extern const char *rindex (const char *__s, int __c)
  68. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  69. # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO
  70. __extern_always_inline char *
  71. rindex (char *__s, int __c) __THROW
  72. {
  73. return __builtin_rindex (__s, __c);
  74. }
  75. __extern_always_inline const char *
  76. rindex (const char *__s, int __c) __THROW
  77. {
  78. return __builtin_rindex (__s, __c);
  79. }
  80. # endif
  81. }
  82. # else
  83. extern char *rindex (const char *__s, int __c)
  84. __THROW __attribute_pure__ __nonnull ((1));
  85. # endif
  86. # endif
  87. #if defined __USE_MISC || !defined __USE_XOPEN2K8 || defined __USE_XOPEN2K8XSI
  88. /* Return the position of the first bit set in I, or 0 if none are set.
  89. The least-significant bit is position 1, the most-significant 32. */
  90. extern int ffs (int __i) __THROW __attribute__ ((const));
  91. #endif
  92. /* Compare S1 and S2, ignoring case. */
  93. extern int strcasecmp (const char *__s1, const char *__s2)
  94. __THROW __attribute_pure__;
  95. /* Compare no more than N chars of S1 and S2, ignoring case. */
  96. extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
  97. __THROW __attribute_pure__;
  98. #ifdef __USE_XOPEN2K8
  99. /* The following functions are equivalent to the both above but they
  100. take the locale they use for the collation as an extra argument.
  101. This is not standardsized but something like will come. */
  102. # include <xlocale.h>
  103. /* Again versions of a few functions which use the given locale instead
  104. of the global one. */
  105. extern int strcasecmp_l (const char *__s1, const char *__s2, __locale_t __loc)
  106. __THROW __attribute_pure__ __nonnull ((1, 2, 3));
  107. extern int strncasecmp_l (const char *__s1, const char *__s2,
  108. size_t __n, __locale_t __loc)
  109. __THROW __attribute_pure__ __nonnull ((1, 2, 4));
  110. #endif
  111. __END_DECLS
  112. #endif /* string.h */
  113. #endif /* strings.h */