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