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 (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 /* Copyright (c) 1988 AT&T */ 27 /* All Rights Reserved */ 28 29 #ifndef _STRING_H 30 #define _STRING_H 31 32 #include <iso/string_iso.h> 33 34 /* 35 * Allow global visibility for symbols defined in 36 * C++ "std" namespace in <iso/string_iso.h>. 37 */ 38 #if __cplusplus >= 199711L 39 using std::size_t; 40 using std::memchr; 41 using std::memcmp; 42 using std::memcpy; 43 using std::memmove; 44 using std::memset; 45 using std::strcat; 46 using std::strchr; 47 using std::strcmp; 48 using std::strcoll; 49 using std::strcpy; 50 using std::strcspn; 51 using std::strerror; 52 using std::strlen; 53 using std::strncat; 54 using std::strncmp; 55 using std::strncpy; 56 using std::strpbrk; 57 using std::strrchr; 58 using std::strspn; 59 using std::strstr; 60 using std::strtok; 61 using std::strxfrm; 62 #endif 63 64 #ifdef __cplusplus 65 extern "C" { 66 #endif 67 68 #if defined(__STDC__) 69 70 #if defined(__EXTENSIONS__) || \ 71 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 72 defined(_XPG6) || defined(_REENTRANT) 73 extern int strerror_r(int, char *, size_t); 74 #endif 75 76 #if defined(__EXTENSIONS__) || \ 77 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 78 (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT) 79 extern char *strtok_r(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, 80 char **_RESTRICT_KYWD); 81 #endif 82 83 #if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \ 84 defined(__XOPEN_OR_POSIX) 85 extern void *memccpy(void *_RESTRICT_KYWD, const void *_RESTRICT_KYWD, 86 int, size_t); 87 #endif 88 89 #if defined(__EXTENSIONS__) || \ 90 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) 91 /* || defined(_XPG7) */ 92 extern int strcasecmp(const char *, const char *); 93 extern int strncasecmp(const char *, const char *, size_t); 94 extern char *stpcpy(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD); 95 extern char *stpncpy(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, size_t); 96 extern char *strndup(const char *, size_t); 97 extern size_t strnlen(const char *, size_t); 98 extern char *strsignal(int); 99 #endif 100 101 #if defined(__EXTENSIONS__) || \ 102 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) 103 extern int uucopy(const void *_RESTRICT_KYWD, void *_RESTRICT_KYWD, size_t); 104 extern int uucopystr(const void *_RESTRICT_KYWD, void *_RESTRICT_KYWD, size_t); 105 extern int ffs(int); 106 extern int ffsl(long); 107 extern int ffsll(long long); 108 extern int fls(int); 109 extern int flsl(long); 110 extern int flsll(long long); 111 extern void *memmem(const void *, size_t, const void *, size_t); 112 extern char *strcasestr(const char *, const char *); 113 extern char *strnstr(const char *, const char *, size_t); 114 extern size_t strlcpy(char *, const char *, size_t); 115 extern size_t strlcat(char *, const char *, size_t); 116 extern char *strsep(char **stringp, const char *delim); 117 extern char *strchrnul(const char *, int); 118 #endif /* defined(__EXTENSIONS__)... */ 119 120 #if defined(__EXTENSIONS__) || \ 121 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 122 defined(_XPG4_2) 123 extern char *strdup(const char *); 124 #endif 125 126 #if defined(__EXTENSIONS__) || \ 127 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) 128 #if defined(__GNUC__) 129 130 /* 131 * gcc provides this inlining facility but Studio C does not. 132 * We should use it exclusively once Studio C also provides it. 133 */ 134 extern void *__builtin_alloca(size_t); 135 136 #define strdupa(s) \ 137 (__extension__( \ 138 { \ 139 char *__str = (char *)(s); \ 140 strcpy((char *)__builtin_alloca(strlen(__str) + 1), __str); \ 141 })) 142 143 #define strndupa(s, n) \ 144 (__extension__( \ 145 { \ 146 char *__str = (char *)(s); \ 147 size_t __len = strnlen(__str, (n)); \ 148 (__str = strncpy((char *)__builtin_alloca(__len + 1), \ 149 __str, __len), \ 150 __str[__len] = '\0', __str); \ 151 })) 152 153 #else /* __GNUC__ */ 154 155 #if defined(unix) /* excludes c99 */ 156 /* 157 * Studio C currently can't do the gcc-style inlining, 158 * so we use thread-local storage instead. 159 */ 160 extern void *__builtin_alloca(size_t); 161 extern __thread char *__strdupa_str; 162 extern __thread size_t __strdupa_len; 163 164 #define strdupa(s) \ 165 (__strdupa_str = (char *)(s), \ 166 strcpy((char *)__builtin_alloca(strlen(__strdupa_str) + 1), \ 167 __strdupa_str)) 168 169 #define strndupa(s, n) \ 170 (__strdupa_str = (char *)(s), \ 171 __strdupa_len = strnlen(__strdupa_str, (n)), \ 172 __strdupa_str = strncpy((char *)__builtin_alloca(__strdupa_len + 1), \ 173 __strdupa_str, __strdupa_len), \ 174 __strdupa_str[__strdupa_len] = '\0', __strdupa_str) 175 #endif /* unix */ 176 177 #endif /* __GNUC__ */ 178 #endif /* __EXTENSIONS__ ... */ 179 180 #else /* __STDC__ */ 181 182 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \ 183 defined(_XPG6) || defined(_REENTRANT) 184 extern int strerror_r(); 185 #endif 186 187 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \ 188 (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT) 189 extern char *strtok_r(); 190 #endif 191 192 #if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \ 193 defined(__XOPEN_OR_POSIX) 194 extern void *memccpy(); 195 #endif 196 197 #if defined(__EXTENSIONS__) || \ 198 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) 199 /* || defined(_XPG7) */ 200 extern int strcasecmp(); 201 extern int strncasecmp(); 202 extern char *stpcpy(); 203 extern char *stpncpy(); 204 extern char *strndup(); 205 extern size_t strnlen(); 206 extern char *strsignal(); 207 #endif 208 209 #if defined(__EXTENSIONS__) || \ 210 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) 211 extern int uucopy(); 212 extern int uucopystr(); 213 extern int ffs(); 214 extern int ffsl(); 215 extern int ffsll(); 216 extern int fls(); 217 extern int flsl(); 218 extern int flsll(); 219 extern char *strcasestr(); 220 extern char *strnstr(); 221 extern size_t strlcpy(); 222 extern size_t strlcat(); 223 extern char *strsep(); 224 extern char *strchrnul(); 225 #endif /* defined(__EXTENSIONS__) ... */ 226 227 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) 228 extern char *strdup(); 229 #endif 230 231 #endif /* __STDC__ */ 232 233 #ifdef __cplusplus 234 } 235 #endif 236 237 #endif /* _STRING_H */