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