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
65extern "C" {
66#endif
67
68#if __cplusplus >= 199711L
69namespace 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)
89typedef	int	wchar_t;
90#else
91typedef	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)
99typedef	int	wint_t;
100#else
101typedef	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)
108typedef	unsigned long	size_t;		/* size of something in bytes */
109#else
110typedef 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
134typedef __mbstate_t	mbstate_t;
135#endif	/* _MBSTATE_T */
136
137#if defined(_XPG4) && !defined(_FILEDEFED) || __cplusplus >= 199711L
138#define	_FILEDEFED
139typedef __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 */
182extern wint_t __fgetwc_xpg5(__FILE *);
183extern wint_t __getwc_xpg5(__FILE *);
184extern wint_t __getwchar_xpg5(void);
185extern wint_t __fputwc_xpg5(wint_t, __FILE *);
186extern wint_t __putwc_xpg5(wint_t, __FILE *);
187extern wint_t __putwchar_xpg5(wint_t);
188extern wchar_t *__fgetws_xpg5(wchar_t *_RESTRICT_KYWD, int,
189			__FILE *_RESTRICT_KYWD);
190extern int __fputws_xpg5(const wchar_t *_RESTRICT_KYWD, __FILE *_RESTRICT_KYWD);
191extern 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
205extern wint_t fgetwc(__FILE *);
206extern wchar_t *fgetws(wchar_t *_RESTRICT_KYWD, int, __FILE *_RESTRICT_KYWD);
207extern wint_t fputwc(wint_t, __FILE *);
208extern int fputws(const wchar_t *_RESTRICT_KYWD, __FILE *_RESTRICT_KYWD);
209extern wint_t ungetwc(wint_t, __FILE *);
210extern wint_t getwc(__FILE *);
211extern wint_t getwchar(void);
212extern wint_t putwc(wint_t, __FILE *);
213extern wint_t putwchar(wint_t);
214extern double wcstod(const wchar_t *_RESTRICT_KYWD, wchar_t **_RESTRICT_KYWD);
215extern long wcstol(const wchar_t *_RESTRICT_KYWD, wchar_t **_RESTRICT_KYWD,
216	int);
217extern unsigned long wcstoul(const wchar_t *_RESTRICT_KYWD,
218	wchar_t **_RESTRICT_KYWD, int);
219extern wchar_t *wcscat(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD);
220extern int wcscmp(const wchar_t *, const wchar_t *);
221extern int wcscoll(const wchar_t *, const wchar_t *);
222extern wchar_t *wcscpy(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD);
223extern size_t wcscspn(const wchar_t *, const wchar_t *);
224extern size_t wcslen(const wchar_t *);
225extern wchar_t *wcsncat(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
226	size_t);
227extern int wcsncmp(const wchar_t *, const wchar_t *, size_t);
228extern wchar_t *wcsncpy(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
229	size_t);
230extern size_t wcsspn(const wchar_t *, const wchar_t *);
231extern size_t wcsxfrm(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
232	size_t);
233#if __cplusplus >= 199711L
234extern const wchar_t *wcschr(const wchar_t *, wchar_t);
235extern "C++" {
236	inline wchar_t *wcschr(wchar_t *__ws, wchar_t __wc) {
237		return (wchar_t *)wcschr((const wchar_t *)__ws, __wc);
238	}
239}
240extern const wchar_t *wcspbrk(const wchar_t *, const wchar_t *);
241extern "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}
246extern const wchar_t *wcsrchr(const wchar_t *, wchar_t);
247extern "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 */
253extern wchar_t *wcschr(const wchar_t *, wchar_t);
254extern wchar_t *wcspbrk(const wchar_t *, const wchar_t *);
255extern 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 */
260extern wchar_t *wcstok(wchar_t *, const wchar_t *);
261extern 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
266extern wchar_t *wcstok(wchar_t *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
267	wchar_t **_RESTRICT_KYWD);
268extern 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 */
271extern wchar_t *__wcstok_xpg5(wchar_t *_RESTRICT_KYWD,
272	const wchar_t *_RESTRICT_KYWD, wchar_t **_RESTRICT_KYWD);
273extern 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)
283extern wint_t	btowc(int);
284extern int	fwprintf(__FILE *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
285			...);
286extern int	fwscanf(__FILE *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
287			...);
288extern int	fwide(__FILE *, int);
289extern int	mbsinit(const mbstate_t *);
290extern size_t	mbrlen(const char *_RESTRICT_KYWD, size_t,
291			mbstate_t *_RESTRICT_KYWD);
292extern size_t	mbrtowc(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
293			size_t, mbstate_t *_RESTRICT_KYWD);
294extern size_t	mbsrtowcs(wchar_t *_RESTRICT_KYWD, const char **_RESTRICT_KYWD,
295			size_t, mbstate_t *_RESTRICT_KYWD);
296extern int	swprintf(wchar_t *_RESTRICT_KYWD, size_t,
297			const wchar_t *_RESTRICT_KYWD, ...);
298extern int	swscanf(const wchar_t *_RESTRICT_KYWD,
299			const wchar_t *_RESTRICT_KYWD, ...);
300extern int	vfwprintf(__FILE *_RESTRICT_KYWD, const wchar_t *_RESTRICT_KYWD,
301			__va_list);
302extern int	vwprintf(const wchar_t *_RESTRICT_KYWD, __va_list);
303extern int	vswprintf(wchar_t *_RESTRICT_KYWD, size_t,
304			const wchar_t *_RESTRICT_KYWD, __va_list);
305extern size_t	wcrtomb(char *_RESTRICT_KYWD, wchar_t,
306			mbstate_t *_RESTRICT_KYWD);
307extern 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)
310extern size_t	wcsnrtombs(char *_RESTRICT_KYWD, const wchar_t **_RESTRICT_KYWD,
311			size_t, size_t, mbstate_t *_RESTRICT_KYWD);
312#endif
313extern int	wctob(wint_t);
314extern int	wmemcmp(const wchar_t *, const wchar_t *, size_t);
315extern wchar_t	*wmemcpy(wchar_t *_RESTRICT_KYWD,
316			const wchar_t *_RESTRICT_KYWD, size_t);
317extern wchar_t	*wmemmove(wchar_t *, const wchar_t *, size_t);
318extern wchar_t	*wmemset(wchar_t *, wchar_t, size_t);
319extern int	wprintf(const wchar_t *_RESTRICT_KYWD, ...);
320extern int	wscanf(const wchar_t *_RESTRICT_KYWD, ...);
321#if __cplusplus >= 199711L
322extern const wchar_t *wcsstr(const wchar_t *, const wchar_t *);
323extern "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}
328extern const wchar_t *wmemchr(const wchar_t *, wchar_t, size_t);
329extern "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 */
335extern wchar_t	*wcsstr(const wchar_t *_RESTRICT_KYWD,
336	const wchar_t *_RESTRICT_KYWD);
337extern 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