Update feature guard for strdup/strndup in <bits/string2.h>
[glibc.git] / string / strings.h
blob872a0b252a21c392b92f04eb8efaa413197e6b08
1 /* Copyright (C) 1991-2014 Free Software Foundation, Inc.
2 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.
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.
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/>. */
18 #ifndef _STRINGS_H
19 #define _STRINGS_H 1
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
26 # include <features.h>
27 # define __need_size_t
28 # include <stddef.h>
30 /* Provide correct C++ prototypes, and indicate this to the caller. This
31 requires a compatible C++ standard library. As a heuristic, we provide
32 these when the compiler indicates full conformance with C++98 or later,
33 and for older GCC versions that are known to provide a compatible
34 libstdc++. */
35 # if defined __cplusplus && (__cplusplus >= 199711L || __GNUC_PREREQ (4, 4))
36 # define __CORRECT_ISO_CPP_STRINGS_H_PROTO
37 # endif
39 __BEGIN_DECLS
41 # if defined __USE_MISC || !defined __USE_XOPEN2K8
42 /* Compare N bytes of S1 and S2 (same as memcmp). */
43 extern int bcmp (const void *__s1, const void *__s2, size_t __n)
44 __THROW __attribute_pure__;
46 /* Copy N bytes of SRC to DEST (like memmove, but args reversed). */
47 extern void bcopy (const void *__src, void *__dest, size_t __n) __THROW;
49 /* Set N bytes of S to 0. */
50 extern void bzero (void *__s, size_t __n) __THROW;
52 /* Find the first occurrence of C in S (same as strchr). */
53 # ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO
54 extern "C++"
56 extern char *index (char *__s, int __c)
57 __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
58 extern const char *index (const char *__s, int __c)
59 __THROW __asm ("index") __attribute_pure__ __nonnull ((1));
61 # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO
62 __extern_always_inline char *
63 index (char *__s, int __c) __THROW
65 return __builtin_index (__s, __c);
68 __extern_always_inline const char *
69 index (const char *__s, int __c) __THROW
71 return __builtin_index (__s, __c);
73 # endif
75 # else
76 extern char *index (const char *__s, int __c)
77 __THROW __attribute_pure__ __nonnull ((1));
78 # endif
80 /* Find the last occurrence of C in S (same as strrchr). */
81 # ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO
82 extern "C++"
84 extern char *rindex (char *__s, int __c)
85 __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
86 extern const char *rindex (const char *__s, int __c)
87 __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1));
89 # if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO
90 __extern_always_inline char *
91 rindex (char *__s, int __c) __THROW
93 return __builtin_rindex (__s, __c);
96 __extern_always_inline const char *
97 rindex (const char *__s, int __c) __THROW
99 return __builtin_rindex (__s, __c);
101 # endif
103 # else
104 extern char *rindex (const char *__s, int __c)
105 __THROW __attribute_pure__ __nonnull ((1));
106 # endif
107 # endif
109 #if defined __USE_MISC || !defined __USE_XOPEN2K8 || defined __USE_XOPEN2K8XSI
110 /* Return the position of the first bit set in I, or 0 if none are set.
111 The least-significant bit is position 1, the most-significant 32. */
112 extern int ffs (int __i) __THROW __attribute__ ((const));
113 #endif
115 /* Compare S1 and S2, ignoring case. */
116 extern int strcasecmp (const char *__s1, const char *__s2)
117 __THROW __attribute_pure__;
119 /* Compare no more than N chars of S1 and S2, ignoring case. */
120 extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
121 __THROW __attribute_pure__;
123 #ifdef __USE_XOPEN2K8
124 /* The following functions are equivalent to the both above but they
125 take the locale they use for the collation as an extra argument.
126 This is not standardsized but something like will come. */
127 # include <xlocale.h>
129 /* Again versions of a few functions which use the given locale instead
130 of the global one. */
131 extern int strcasecmp_l (const char *__s1, const char *__s2, __locale_t __loc)
132 __THROW __attribute_pure__ __nonnull ((1, 2, 3));
134 extern int strncasecmp_l (const char *__s1, const char *__s2,
135 size_t __n, __locale_t __loc)
136 __THROW __attribute_pure__ __nonnull ((1, 2, 4));
137 #endif
139 __END_DECLS
141 #endif /* string.h */
143 #endif /* strings.h */