5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
25 */
26
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
29
30 #ifndef _STRING_H
31 #define _STRING_H
32
33 #include <iso/string_iso.h>
34
35 /*
36 * Allow global visibility for symbols defined in
37 * C++ "std" namespace in <iso/string_iso.h>.
38 */
39 #if __cplusplus >= 199711L
40 using std::size_t;
41 using std::memchr;
42 using std::memcmp;
43 using std::memcpy;
44 using std::memmove;
122 extern void *memmem(const void *, size_t, const void *, size_t);
123 extern char *strcasestr(const char *, const char *);
124 extern char *strnstr(const char *, const char *, size_t);
125 extern size_t strlcpy(char *, const char *, size_t);
126 extern size_t strlcat(char *, const char *, size_t);
127 extern char *strsep(char **stringp, const char *delim);
128 extern char *strchrnul(const char *, int);
129 extern char *strcasestr_l(const char *, const char *, locale_t);
130 extern int strcasecmp(const char *, const char *);
131 extern int strncasecmp(const char *, const char *, size_t);
132 #endif /* defined(__EXTENSIONS__)... */
133
134 #if defined(__EXTENSIONS__) || \
135 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
136 defined(_XPG4_2)
137 extern char *strdup(const char *);
138 #endif
139
140 #if defined(__EXTENSIONS__) || \
141 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
142 #if defined(__GNUC__)
143
144 /*
145 * gcc provides this inlining facility but Studio C does not.
146 * We should use it exclusively once Studio C also provides it.
147 */
148 extern void *__builtin_alloca(size_t);
149
150 #define strdupa(s) \
151 (__extension__( \
152 { \
153 char *__str = (char *)(s); \
154 strcpy((char *)__builtin_alloca(strlen(__str) + 1), __str); \
155 }))
156
157 #define strndupa(s, n) \
158 (__extension__( \
159 { \
160 char *__str = (char *)(s); \
161 size_t __len = strnlen(__str, (n)); \
162 (__str = strncpy((char *)__builtin_alloca(__len + 1), \
163 __str, __len), \
164 __str[__len] = '\0', __str); \
165 }))
166
167 #else /* __GNUC__ */
168
169 #if defined(unix) /* excludes c99 */
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Copyright 2020 Joyent, Inc.
26 */
27
28 /* Copyright (c) 1988 AT&T */
29 /* All Rights Reserved */
30
31 #ifndef _STRING_H
32 #define _STRING_H
33
34 #include <iso/string_iso.h>
35
36 /*
37 * Allow global visibility for symbols defined in
38 * C++ "std" namespace in <iso/string_iso.h>.
39 */
40 #if __cplusplus >= 199711L
41 using std::size_t;
42 using std::memchr;
43 using std::memcmp;
44 using std::memcpy;
45 using std::memmove;
123 extern void *memmem(const void *, size_t, const void *, size_t);
124 extern char *strcasestr(const char *, const char *);
125 extern char *strnstr(const char *, const char *, size_t);
126 extern size_t strlcpy(char *, const char *, size_t);
127 extern size_t strlcat(char *, const char *, size_t);
128 extern char *strsep(char **stringp, const char *delim);
129 extern char *strchrnul(const char *, int);
130 extern char *strcasestr_l(const char *, const char *, locale_t);
131 extern int strcasecmp(const char *, const char *);
132 extern int strncasecmp(const char *, const char *, size_t);
133 #endif /* defined(__EXTENSIONS__)... */
134
135 #if defined(__EXTENSIONS__) || \
136 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
137 defined(_XPG4_2)
138 extern char *strdup(const char *);
139 #endif
140
141 #if defined(__EXTENSIONS__) || \
142 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
143
144 #if defined(__GNUC__)
145
146 #define strdupa(s) \
147 (__extension__( \
148 { \
149 char *__str = (char *)(s); \
150 strcpy((char *)__builtin_alloca(strlen(__str) + 1), __str); \
151 }))
152
153 #define strndupa(s, n) \
154 (__extension__( \
155 { \
156 char *__str = (char *)(s); \
157 size_t __len = strnlen(__str, (n)); \
158 (__str = strncpy((char *)__builtin_alloca(__len + 1), \
159 __str, __len), \
160 __str[__len] = '\0', __str); \
161 }))
162
163 #else /* __GNUC__ */
164
165 #if defined(unix) /* excludes c99 */
|