Merge commit '37e84ab74e939caf52150fc3352081786ecc0c29' into merges
[unleashed.git] / include / string.h
blobd009fd2692dbfb51c50b270c1c6cd94da1548d58
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #ifndef _STRING_H
31 #define _STRING_H
33 #include <iso/string_iso.h>
36 * Allow global visibility for symbols defined in
37 * C++ "std" namespace in <iso/string_iso.h>.
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;
45 using std::memset;
46 using std::strcat;
47 using std::strchr;
48 using std::strcmp;
49 using std::strcoll;
50 using std::strcpy;
51 using std::strcspn;
52 using std::strerror;
53 using std::strlen;
54 using std::strncat;
55 using std::strncmp;
56 using std::strncpy;
57 using std::strpbrk;
58 using std::strrchr;
59 using std::strspn;
60 using std::strstr;
61 using std::strtok;
62 using std::strxfrm;
63 #endif
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
69 extern int strerror_r(int, char *, size_t);
71 extern char *strtok_r(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
72 char **_RESTRICT_KYWD);
74 #if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \
75 defined(__XOPEN_OR_POSIX)
76 extern void *memccpy(void *_RESTRICT_KYWD, const void *_RESTRICT_KYWD,
77 int, size_t);
78 #endif
80 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
82 extern char *stpcpy(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD);
83 extern char *stpncpy(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, size_t);
84 extern char *strndup(const char *, size_t);
85 extern size_t strnlen(const char *, size_t);
86 extern char *strsignal(int);
88 #ifndef _LOCALE_T
89 #define _LOCALE_T
90 typedef struct _locale *locale_t;
91 #endif
93 extern int strcoll_l(const char *, const char *, locale_t);
94 extern size_t strxfrm_l(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
95 size_t, locale_t);
96 extern int strcasecmp_l(const char *, const char *, locale_t);
97 extern int strncasecmp_l(const char *, const char *, size_t, locale_t);
98 extern char *strerror_l(int, locale_t);
100 #endif /* defined(_STRICT_SYMBOLS) || defined(_XPG7) */
102 #if !defined(_STRICT_SYMBOLS)
104 /* Note that some of these are also declared in strings.h for XPG4_2+ */
105 extern void explicit_bzero(void *, size_t);
106 extern int uucopy(const void *_RESTRICT_KYWD, void *_RESTRICT_KYWD, size_t);
107 extern int uucopystr(const void *_RESTRICT_KYWD, void *_RESTRICT_KYWD, size_t);
108 extern int ffs(int);
109 extern int ffsl(long);
110 extern int ffsll(long long);
111 extern int fls(int);
112 extern int flsl(long);
113 extern int flsll(long long);
114 extern void *memmem(const void *, size_t, const void *, size_t);
115 extern char *strcasestr(const char *, const char *);
116 extern char *strnstr(const char *, const char *, size_t);
117 extern size_t strlcpy(char *, const char *, size_t);
118 extern size_t strlcat(char *, const char *, size_t);
119 extern char *strsep(char **stringp, const char *delim);
120 extern char *strchrnul(const char *, int);
121 extern char *strcasestr_l(const char *, const char *, locale_t);
122 extern int strcasecmp(const char *, const char *);
123 extern int strncasecmp(const char *, const char *, size_t);
124 #endif /* defined(__EXTENSIONS__)... */
126 #if defined(__EXTENSIONS__) || \
127 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
128 defined(_XPG4_2)
129 extern char *strdup(const char *);
130 #endif
132 #if defined(__EXTENSIONS__) || \
133 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
134 #if defined(__GNUC__)
137 * gcc provides this inlining facility but Studio C does not.
138 * We should use it exclusively once Studio C also provides it.
140 extern void *__builtin_alloca(size_t);
142 #define strdupa(s) \
143 (__extension__( \
145 char *__str = (char *)(s); \
146 strcpy((char *)__builtin_alloca(strlen(__str) + 1), __str); \
149 #define strndupa(s, n) \
150 (__extension__( \
152 char *__str = (char *)(s); \
153 size_t __len = strnlen(__str, (n)); \
154 (__str = strncpy((char *)__builtin_alloca(__len + 1), \
155 __str, __len), \
156 __str[__len] = '\0', __str); \
159 #else /* __GNUC__ */
161 #if defined(unix) /* excludes c99 */
163 * Studio C currently can't do the gcc-style inlining,
164 * so we use thread-local storage instead.
166 extern void *__builtin_alloca(size_t);
167 extern __thread char *__strdupa_str;
168 extern __thread size_t __strdupa_len;
170 #define strdupa(s) \
171 (__strdupa_str = (char *)(s), \
172 strcpy((char *)__builtin_alloca(strlen(__strdupa_str) + 1), \
173 __strdupa_str))
175 #define strndupa(s, n) \
176 (__strdupa_str = (char *)(s), \
177 __strdupa_len = strnlen(__strdupa_str, (n)), \
178 __strdupa_str = strncpy((char *)__builtin_alloca(__strdupa_len + 1), \
179 __strdupa_str, __strdupa_len), \
180 __strdupa_str[__strdupa_len] = '\0', __strdupa_str)
181 #endif /* unix */
183 #endif /* __GNUC__ */
184 #endif /* __EXTENSIONS__ ... */
186 #ifdef __cplusplus
188 #endif
190 #endif /* _STRING_H */