xref: /illumos-gate/usr/src/head/iso/wchar_iso.h (revision b10f758d69dd151326d3859af7e1d857ec9a6355)
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 2014 PALO, Richard.
25  *
26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 /*
31  * An application should not include this header directly.  Instead it
32  * should be included only through the inclusion of other Sun headers.
33  *
34  * The contents of this header is limited to identifiers specified in the
35  * C Standard.  Any new identifiers specified in future amendments to the
36  * C Standard must be placed in this header.  If these new identifiers
37  * are required to also be in the C++ Standard "std" namespace, then for
38  * anything other than macro definitions, corresponding "using" directives
39  * must also be added to <wchar.h>.
40  */
41 
42 #ifndef	_ISO_WCHAR_ISO_H
43 #define	_ISO_WCHAR_ISO_H
44 
45 #include <sys/feature_tests.h>
46 #include <sys/null.h>
47 #include <stdio_tag.h>
48 #include <wchar_impl.h>
49 #include <iso/time_iso.h>
50 
51 #if (defined(__cplusplus) && (__cplusplus - 0 < 54321L)) || \
52 	(!defined(__cplusplus) && !defined(_STRICT_STDC)) || \
53 	defined(__EXTENSIONS__)
54 #include <stdio.h>
55 #endif  /*  (defined(__cplusplus) && (__cplusplus - 0 < 54321L)) ... */
56 
57 #if !defined(_STRICT_STDC) || defined(__EXTENSIONS__)
58 #include <ctype.h>
59 #include <stddef.h>
60 #endif /* !defined(_STRICT_STDC) || defined(__EXTENSIONS__) */
61 
62 #include <sys/va_list.h>
63 
64 #ifdef	__cplusplus
65 extern "C" {
66 #endif
67 
68 #if __cplusplus >= 199711L
69 namespace std {
70 #endif
71 
72 /*
73  * wchar_t is a built-in type in standard C++ and as such is not
74  * defined here when using standard C++. However, the GNU compiler
75  * fixincludes utility nonetheless creates its own version of this
76  * header for use by gcc and g++. In that version it adds a redundant
77  * guard for __cplusplus. To avoid the creation of a gcc/g++ specific
78  * header we need to include the following magic comment:
79  *
80  * we must use the C++ compiler's type
81  *
82  * The above comment should not be removed or changed until GNU
83  * gcc/fixinc/inclhack.def is updated to bypass this header.
84  */
85 #if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__))
86 #ifndef _WCHAR_T
87 #define	_WCHAR_T
88 #if defined(_LP64)
89 typedef	int	wchar_t;
90 #else
91 typedef	long	wchar_t;
92 #endif
93 #endif	/* !_WCHAR_T */
94 #endif	/* !defined(__cplusplus) ... */
95 
96 #if !defined(_WINT_T) || __cplusplus >= 199711L
97 #define	_WINT_T
98 #if defined(_LP64)
99 typedef	int	wint_t;
100 #else
101 typedef	long	wint_t;
102 #endif
103 #endif	/* !defined(_WINT_T) || __cplusplus >= 199711L */
104 
105 #if !defined(_SIZE_T) || __cplusplus >= 199711L
106 #define	_SIZE_T
107 #if defined(_LP64) || defined(_I32LPx)
108 typedef	unsigned long	size_t;		/* size of something in bytes */
109 #else
110 typedef unsigned int	size_t;		/* (historical version) */
111 #endif
112 #endif  /* !defined(_SIZE_T) || __cplusplus >= 199711L */
113 
114 #ifndef WEOF
115 #if __cplusplus >= 199711L
116 #define	WEOF	((std::wint_t)(-1))
117 #else
118 #define	WEOF	((wint_t)(-1))
119 #endif
120 #endif /* WEOF */
121 
122 /* not XPG4 and not XPG4v2 */
123 #if !defined(_XPG4) || defined(_XPG5)
124 #ifndef	WCHAR_MAX
125 #define	WCHAR_MAX	2147483647
126 #endif
127 #ifndef	WCHAR_MIN
128 #define	WCHAR_MIN	(-2147483647-1)
129 #endif
130 #endif /* not XPG4 and not XPG4v2 */
131 
132 #if !defined(_MBSTATE_T) || __cplusplus >= 199711L
133 #define	_MBSTATE_T
134 typedef __mbstate_t	mbstate_t;
135 #endif	/* _MBSTATE_T */
136 
137 #if defined(_XPG4) && !defined(_FILEDEFED) || __cplusplus >= 199711L
138 #define	_FILEDEFED
139 typedef __FILE FILE;
140 #endif
141 
142 #if !defined(_LP64) && !defined(_LONGLONG_TYPE)
143 
144 #ifdef __PRAGMA_REDEFINE_EXTNAME
145 #pragma	redefine_extname fwprintf	_fwprintf_c89
146 #pragma	redefine_extname swprintf	_swprintf_c89
147 #pragma	redefine_extname vfwprintf	_vfwprintf_c89
148 #pragma	redefine_extname vswprintf	_vswprintf_c89
149 #pragma	redefine_extname vwprintf	_vwprintf_c89
150 #pragma	redefine_extname wprintf	_wprintf_c89
151 #pragma	redefine_extname fwscanf	_fwscanf_c89
152 #pragma	redefine_extname swscanf	_swscanf_c89
153 #pragma	redefine_extname wscanf		_wscanf_c89
154 #else
155 #define	fwprintf	_fwprintf_c89
156 #define	swprintf	_swprintf_c89
157 #define	vfwprintf	_vfwprintf_c89
158 #define	vswprintf	_vswprintf_c89
159 #define	vwprintf	_vwprintf_c89
160 #define	wprintf		_wprintf_c89
161 #define	fwscanf		_fwscanf_c89
162 #define	swscanf		_swscanf_c89
163 #define	wscanf		_wscanf_c89
164 #endif
165 
166 #endif /* !defined(_LP64) && !defined(_LONGLONG_TYPE) */
167 
168 #if (!defined(_MSE_INT_H))
169 /* not XPG4 and not XPG4v2 */
170 #if !defined(_XPG4) || defined(_XPG5)
171 #ifdef __PRAGMA_REDEFINE_EXTNAME
172 #pragma redefine_extname fgetwc	__fgetwc_xpg5
173 #pragma redefine_extname getwc	__getwc_xpg5
174 #pragma redefine_extname getwchar	__getwchar_xpg5
175 #pragma redefine_extname fputwc	__fputwc_xpg5
176 #pragma redefine_extname putwc	__putwc_xpg5
177 #pragma redefine_extname putwchar	__putwchar_xpg5
178 #pragma redefine_extname fgetws	__fgetws_xpg5
179 #pragma redefine_extname fputws	__fputws_xpg5
180 #pragma redefine_extname ungetwc	__ungetwc_xpg5
181 #else	/* __PRAGMA_REDEFINE_EXTNAME */
182 extern wint_t __fgetwc_xpg5(__FILE *);
183 extern wint_t __getwc_xpg5(__FILE *);
184 extern wint_t __getwchar_xpg5(void);
185 extern wint_t __fputwc_xpg5(wint_t, __FILE *);
186 extern wint_t __putwc_xpg5(wint_t, __FILE *);
187 extern wint_t __putwchar_xpg5(wint_t);
188 extern wchar_t *__fgetws_xpg5(wchar_t *_RESTRICT_KYWD, int,
189 			__FILE *_RESTRICT_KYWD);
190 extern int __fputws_xpg5(const wchar_t *_RESTRICT_KYWD, __FILE *_RESTRICT_KYWD);
191 extern wint_t __ungetwc_xpg5(wint_t, __FILE *);
192 #define	fgetwc	__fgetwc_xpg5
193 #define	getwc	__getwc_xpg5
194 #define	getwchar	__getwchar_xpg5
195 #define	fputwc	__fputwc_xpg5
196 #define	putwc	__putwc_xpg5
197 #define	putwchar	__putwchar_xpg5
198 #define	fgetws	__fgetws_xpg5
199 #define	fputws	__fputws_xpg5
200 #define	ungetwc	__ungetwc_xpg5
201 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
202 #endif /* not XPG4 and not XPG4v2 */
203 #endif /* defined(_MSE_INT_H) */
204 
205 extern wint_t fgetwc(__FILE *);
206 extern wchar_t *fgetws(wchar_t *_RESTRICT_KYWD, int, __FILE *_RESTRICT_KYWD);
207 extern wint_t fputwc(wint_t, __FILE *);
208 extern int fputws(const wchar_t *_RESTRICT_KYWD, __FILE *_RESTRICT_KYWD);
209 extern wint_t ungetwc(wint_t, __FILE *);
210 extern wint_t getwc(__FILE *);
211 extern wint_t getwchar(void);
212 extern wint_t putwc(wint_t, __FILE *);
213 extern wint_t putwchar(wint_t);
214 extern double wcstod(const wchar_t *_RESTRICT_KYWD, wchar_t **_RESTRICT_KYWD);
215 extern long wcstol(const wchar_t *_RESTRICT_KYWD, wchar_t **_RESTRICT_KYWD,
216 	int);
217 extern unsigned long wcstoul(const wchar_t *_RESTRICT_KYWD,
218 	wchar_t **_RESTRICT_KYWD, int);
219 extern wchar_t *wcscat(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD);
220 extern int wcscmp(const wchar_t *, const wchar_t *);
221 extern int wcscoll(const wchar_t *, const wchar_t *);
222 extern wchar_t *wcscpy(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD);
223 extern size_t wcscspn(const wchar_t *, const wchar_t *);
224 extern size_t wcslen(const wchar_t *);
225 extern wchar_t *wcsncat(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
226 	size_t);
227 extern int wcsncmp(const wchar_t *, const wchar_t *, size_t);
228 extern wchar_t *wcsncpy(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
229 	size_t);
230 extern size_t wcsspn(const wchar_t *, const wchar_t *);
231 extern size_t wcsxfrm(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
232 	size_t);
233 #if __cplusplus >= 199711L
234 extern const wchar_t *wcschr(const wchar_t *, wchar_t);
235 extern "C++" {
236 	inline wchar_t *wcschr(wchar_t *__ws, wchar_t __wc) {
237 		return (wchar_t *)wcschr((const wchar_t *)__ws, __wc);
238 	}
239 }
240 extern const wchar_t *wcspbrk(const wchar_t *, const wchar_t *);
241 extern "C++" {
242 	inline wchar_t *wcspbrk(wchar_t *__ws1, const wchar_t *__ws2) {
243 		return (wchar_t *)wcspbrk((const wchar_t *)__ws1, __ws2);
244 	}
245 }
246 extern const wchar_t *wcsrchr(const wchar_t *, wchar_t);
247 extern "C++" {
248 	inline wchar_t *wcsrchr(wchar_t *__ws, wchar_t __wc) {
249 		return (wchar_t *)wcsrchr((const wchar_t *)__ws, __wc);
250 	}
251 }
252 #else /* __cplusplus >= 199711L */
253 extern wchar_t *wcschr(const wchar_t *, wchar_t);
254 extern wchar_t *wcspbrk(const wchar_t *, const wchar_t *);
255 extern wchar_t *wcsrchr(const wchar_t *, wchar_t);
256 #endif /* __cplusplus >= 199711L */
257 
258 #if (!defined(_MSE_INT_H))
259 #if defined(_XPG4) && !defined(_XPG5) /* XPG4 or XPG4v2 */
260 extern wchar_t *wcstok(wchar_t *, const wchar_t *);
261 extern size_t wcsftime(wchar_t *, size_t, const char *, const struct tm *);
262 #else	/* XPG4 or XPG4v2 */
263 #ifdef __PRAGMA_REDEFINE_EXTNAME
264 #pragma redefine_extname wcstok	__wcstok_xpg5
265 #pragma redefine_extname wcsftime	__wcsftime_xpg5
266 extern wchar_t *wcstok(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
267 	wchar_t **_RESTRICT_KYWD);
268 extern size_t wcsftime(wchar_t *_RESTRICT_KYWD, size_t,
269 	const wchar_t *_RESTRICT_KYWD, const struct tm *_RESTRICT_KYWD);
270 #else	/* __PRAGMA_REDEFINE_EXTNAME */
271 extern wchar_t *__wcstok_xpg5(wchar_t *_RESTRICT_KYWD,
272 	const wchar_t *_RESTRICT_KYWD, wchar_t **_RESTRICT_KYWD);
273 extern size_t __wcsftime_xpg5(wchar_t *_RESTRICT_KYWD, size_t,
274 	const wchar_t *_RESTRICT_KYWD, const struct tm *_RESTRICT_KYWD);
275 #define	wcstok	__wcstok_xpg5
276 #define	wcsftime	__wcsftime_xpg5
277 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
278 #endif	/* XPG4 or XPG4v2 */
279 #endif	/* !defined(_MSE_INT_H) */
280 
281 /* not XPG4 and not XPG4v2 */
282 #if !defined(_XPG4) || defined(_XPG5)
283 extern wint_t	btowc(int);
284 extern int	fwprintf(__FILE *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
285 			...);
286 extern int	fwscanf(__FILE *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
287 			...);
288 extern int	fwide(__FILE *, int);
289 extern int	mbsinit(const mbstate_t *);
290 extern size_t	mbrlen(const char *_RESTRICT_KYWD, size_t,
291 			mbstate_t *_RESTRICT_KYWD);
292 extern size_t	mbrtowc(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
293 			size_t, mbstate_t *_RESTRICT_KYWD);
294 extern size_t	mbsrtowcs(wchar_t *_RESTRICT_KYWD, const char **_RESTRICT_KYWD,
295 			size_t, mbstate_t *_RESTRICT_KYWD);
296 extern int	swprintf(wchar_t *_RESTRICT_KYWD, size_t,
297 			const wchar_t *_RESTRICT_KYWD, ...);
298 extern int	swscanf(const wchar_t *_RESTRICT_KYWD,
299 			const wchar_t *_RESTRICT_KYWD, ...);
300 extern int	vfwprintf(__FILE *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
301 			__va_list);
302 extern int	vwprintf(const wchar_t *_RESTRICT_KYWD, __va_list);
303 extern int	vswprintf(wchar_t *_RESTRICT_KYWD, size_t,
304 			const wchar_t *_RESTRICT_KYWD, __va_list);
305 extern size_t	wcrtomb(char *_RESTRICT_KYWD, wchar_t,
306 			mbstate_t *_RESTRICT_KYWD);
307 extern size_t	wcsrtombs(char *_RESTRICT_KYWD, const wchar_t **_RESTRICT_KYWD,
308 			size_t, mbstate_t *_RESTRICT_KYWD);
309 #if defined(_XPG7) || !defined(_STRICT_SYMBOLS)
310 extern size_t	wcsnrtombs(char *_RESTRICT_KYWD, const wchar_t **_RESTRICT_KYWD,
311 			size_t, size_t, mbstate_t *_RESTRICT_KYWD);
312 #endif
313 extern int	wctob(wint_t);
314 extern int	wmemcmp(const wchar_t *, const wchar_t *, size_t);
315 extern wchar_t	*wmemcpy(wchar_t *_RESTRICT_KYWD,
316 			const wchar_t *_RESTRICT_KYWD, size_t);
317 extern wchar_t	*wmemmove(wchar_t *, const wchar_t *, size_t);
318 extern wchar_t	*wmemset(wchar_t *, wchar_t, size_t);
319 extern int	wprintf(const wchar_t *_RESTRICT_KYWD, ...);
320 extern int	wscanf(const wchar_t *_RESTRICT_KYWD, ...);
321 #if __cplusplus >= 199711L
322 extern const wchar_t *wcsstr(const wchar_t *, const wchar_t *);
323 extern "C++" {
324 	inline wchar_t *wcsstr(wchar_t *__ws1, const wchar_t *__ws2) {
325 		return (wchar_t *)wcsstr((const wchar_t *)__ws1, __ws2);
326 	}
327 }
328 extern const wchar_t *wmemchr(const wchar_t *, wchar_t, size_t);
329 extern "C++" {
330 	inline wchar_t *wmemchr(wchar_t *__ws, wchar_t __wc, size_t __n) {
331 		return (wchar_t *)wmemchr((const wchar_t *)__ws, __wc, __n);
332 	}
333 }
334 #else /* __cplusplus >= 199711L */
335 extern wchar_t	*wcsstr(const wchar_t *_RESTRICT_KYWD,
336 	const wchar_t *_RESTRICT_KYWD);
337 extern wchar_t	*wmemchr(const wchar_t *, wchar_t, size_t);
338 #endif /* __cplusplus >= 199711L */
339 #endif /* not XPG4 and not XPG4v2 */
340 
341 #if __cplusplus >= 199711L
342 }
343 #endif /* end of namespace std */
344 
345 #ifdef	__cplusplus
346 }
347 #endif
348 
349 #endif	/* _ISO_WCHAR_ISO_H */
350