xref: /titanic_50/usr/src/head/string.h (revision bde3d612a7c090234c60e6e4578821237a5db135)
1 /*
2  * CDDL HEADER START
3  *
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.
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;
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
64 
65 #ifdef	__cplusplus
66 extern "C" {
67 #endif
68 
69 #if defined(__EXTENSIONS__) || \
70 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
71 	defined(_XPG6) || defined(_REENTRANT)
72 extern int strerror_r(int, char *, size_t);
73 #endif
74 
75 #if defined(__EXTENSIONS__) || \
76 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
77 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
78 extern char *strtok_r(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
79 	char **_RESTRICT_KYWD);
80 #endif
81 
82 #if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \
83 	defined(__XOPEN_OR_POSIX)
84 extern void *memccpy(void *_RESTRICT_KYWD, const void *_RESTRICT_KYWD,
85 		int, size_t);
86 #endif
87 
88 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
89 
90 extern char *stpcpy(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD);
91 extern char *stpncpy(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, size_t);
92 extern char *strndup(const char *, size_t);
93 extern size_t strnlen(const char *, size_t);
94 extern char *strsignal(int);
95 
96 #ifndef	_LOCALE_T
97 #define	_LOCALE_T
98 typedef struct _locale *locale_t;
99 #endif
100 
101 extern int strcoll_l(const char *, const char *, locale_t);
102 extern size_t strxfrm_l(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
103     size_t, locale_t);
104 extern int strcasecmp_l(const char *, const char *, locale_t);
105 extern int strncasecmp_l(const char *, const char *, size_t, locale_t);
106 
107 #endif /* defined(_STRICT_SYMBOLS) || defined(_XPG7) */
108 
109 #if !defined(_STRICT_SYMBOLS)
110 
111 /* Note that some of these are also declared in strings.h for XPG4_2+ */
112 extern int uucopy(const void *_RESTRICT_KYWD, void *_RESTRICT_KYWD, size_t);
113 extern int uucopystr(const void *_RESTRICT_KYWD, void *_RESTRICT_KYWD, size_t);
114 extern int ffs(int);
115 extern int ffsl(long);
116 extern int ffsll(long long);
117 extern int fls(int);
118 extern int flsl(long);
119 extern int flsll(long long);
120 extern void *memmem(const void *, size_t, const void *, size_t);
121 extern char *strcasestr(const char *, const char *);
122 extern char *strnstr(const char *, const char *, size_t);
123 extern size_t strlcpy(char *, const char *, size_t);
124 extern size_t strlcat(char *, const char *, size_t);
125 extern char *strsep(char **stringp, const char *delim);
126 extern char *strchrnul(const char *, int);
127 extern char *strcasestr_l(const char *, const char *, locale_t);
128 extern int strcasecmp(const char *, const char *);
129 extern int strncasecmp(const char *, const char *, size_t);
130 #endif /* defined(__EXTENSIONS__)... */
131 
132 #if defined(__EXTENSIONS__) || \
133 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
134 	defined(_XPG4_2)
135 extern char *strdup(const char *);
136 #endif
137 
138 #if defined(__EXTENSIONS__) || \
139 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
140 #if defined(__GNUC__)
141 
142 /*
143  * gcc provides this inlining facility but Studio C does not.
144  * We should use it exclusively once Studio C also provides it.
145  */
146 extern void *__builtin_alloca(size_t);
147 
148 #define	strdupa(s)							\
149 	(__extension__(							\
150 	{								\
151 	char *__str = (char *)(s);					\
152 	strcpy((char *)__builtin_alloca(strlen(__str) + 1), __str);	\
153 	}))
154 
155 #define	strndupa(s, n)							\
156 	(__extension__(							\
157 	{								\
158 	char *__str = (char *)(s);					\
159 	size_t __len = strnlen(__str, (n));				\
160 	(__str = strncpy((char *)__builtin_alloca(__len + 1),		\
161 	    __str, __len),						\
162 	__str[__len] = '\0', __str);					\
163 	}))
164 
165 #else	/* __GNUC__ */
166 
167 #if defined(unix)	/* excludes c99 */
168 /*
169  * Studio C currently can't do the gcc-style inlining,
170  * so we use thread-local storage instead.
171  */
172 extern void *__builtin_alloca(size_t);
173 extern __thread char *__strdupa_str;
174 extern __thread size_t __strdupa_len;
175 
176 #define	strdupa(s)							\
177 	(__strdupa_str = (char *)(s), 					\
178 	strcpy((char *)__builtin_alloca(strlen(__strdupa_str) + 1),	\
179 	    __strdupa_str))
180 
181 #define	strndupa(s, n)							\
182 	(__strdupa_str = (char *)(s),					\
183 	__strdupa_len = strnlen(__strdupa_str, (n)),			\
184 	__strdupa_str = strncpy((char *)__builtin_alloca(__strdupa_len + 1), \
185 	    __strdupa_str, __strdupa_len),				\
186 	__strdupa_str[__strdupa_len] = '\0', __strdupa_str)
187 #endif	/* unix */
188 
189 #endif	/* __GNUC__ */
190 #endif	/* __EXTENSIONS__ ... */
191 
192 #ifdef	__cplusplus
193 }
194 #endif
195 
196 #endif	/* _STRING_H */
197