strings.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* Copyright (C) 1991,1992,1996,1997,1999,2000,2001,2009,2010
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _STRINGS_H
  17. #define _STRINGS_H 1
  18. /* We don't need and should not read this file if <string.h> was already
  19. read. The one exception being that if __USE_BSD isn't defined, then
  20. these aren't defined in string.h, so we need to define them here. */
  21. #if !defined _STRING_H || !defined __USE_BSD
  22. # include <features.h>
  23. # define __need_size_t
  24. # include <stddef.h>
  25. /* Tell the caller that we provide correct C++ prototypes. */
  26. # if defined __cplusplus && __GNUC_PREREQ (4, 4)
  27. # define __CORRECT_ISO_CPP_STRINGS_H_PROTO
  28. # endif
  29. __BEGIN_DECLS
  30. # if defined __USE_MISC || !defined __USE_XOPEN2K8
  31. /* Compare N bytes of S1 and S2 (same as memcmp). */
  32. extern int bcmp (__const void *__s1, __const void *__s2, size_t __n)
  33. __THROW __attribute_pure__;
  34. /* Copy N bytes of SRC to DEST (like memmove, but args reversed). */
  35. extern void bcopy (__const void *__src, void *__dest, size_t __n) __THROW;
  36. /* Set N bytes of S to 0. */
  37. extern void bzero (void *__s, size_t __n) __THROW;
  38. /* Find the first occurrence of C in S (same as strchr). */
  39. # ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO
  40. extern "C++"
  41. {
  42. extern char *index (char *__s, int __c)
  43. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  44. extern __const char *index (__const char *__s, int __c)
  45. __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
  46. # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO
  47. __extern_always_inline char *
  48. index (char *__s, int __c) __THROW
  49. {
  50. return __builtin_index (__s, __c);
  51. }
  52. __extern_always_inline __const char *
  53. index (__const char *__s, int __c) __THROW
  54. {
  55. return __builtin_index (__s, __c);
  56. }
  57. # endif
  58. }
  59. # else
  60. extern char *index (__const char *__s, int __c)
  61. __THROW __attribute_pure__ __nonnull ((1));
  62. # endif
  63. /* Find the last occurrence of C in S (same as strrchr). */
  64. # ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO
  65. extern "C++"
  66. {
  67. extern char *rindex (char *__s, int __c)
  68. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  69. extern __const char *rindex (__const char *__s, int __c)
  70. __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
  71. # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO
  72. __extern_always_inline char *
  73. rindex (char *__s, int __c) __THROW
  74. {
  75. return __builtin_rindex (__s, __c);
  76. }
  77. __extern_always_inline __const char *
  78. rindex (__const char *__s, int __c) __THROW
  79. {
  80. return __builtin_rindex (__s, __c);
  81. }
  82. # endif
  83. }
  84. # else
  85. extern char *rindex (__const char *__s, int __c)
  86. __THROW __attribute_pure__ __nonnull ((1));
  87. # endif
  88. # endif
  89. #if defined __USE_MISC || !defined __USE_XOPEN2K8 || defined __USE_XOPEN2K8XSI
  90. /* Return the position of the first bit set in I, or 0 if none are set.
  91. The least-significant bit is position 1, the most-significant 32. */
  92. extern int ffs (int __i) __THROW __attribute__ ((const));
  93. #endif
  94. /* Compare S1 and S2, ignoring case. */
  95. extern int strcasecmp (__const char *__s1, __const char *__s2)
  96. __THROW __attribute_pure__;
  97. /* Compare no more than N chars of S1 and S2, ignoring case. */
  98. extern int strncasecmp (__const char *__s1, __const char *__s2, size_t __n)
  99. __THROW __attribute_pure__;
  100. #ifdef __USE_XOPEN2K8
  101. /* The following functions are equivalent to the both above but they
  102. take the locale they use for the collation as an extra argument.
  103. This is not standardsized but something like will come. */
  104. # include <xlocale.h>
  105. /* Again versions of a few functions which use the given locale instead
  106. of the global one. */
  107. extern int strcasecmp_l (__const char *__s1, __const char *__s2,
  108. __locale_t __loc)
  109. __THROW __attribute_pure__ __nonnull ((1, 2, 3));
  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. #endif /* string.h */
  116. #endif /* strings.h */