1/*	$NetBSD: wchar.h,v 1.45 2023/07/31 17:38:28 christos Exp $	*/
2
3/*-
4 * Copyright (c)1999 Citrus Project,
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29/*-
30 * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
31 * All rights reserved.
32 *
33 * This code is derived from software contributed to The NetBSD Foundation
34 * by Julian Coleman.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 *    notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 *    notice, this list of conditions and the following disclaimer in the
43 *    documentation and/or other materials provided with the distribution.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
46 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
47 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
49 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55 * POSSIBILITY OF SUCH DAMAGE.
56 */
57
58#ifndef _WCHAR_H_
59#define _WCHAR_H_
60
61#include <sys/cdefs.h>
62#include <sys/featuretest.h>
63#include <machine/wchar_limits.h>
64#include <sys/ansi.h>
65#include <sys/null.h>
66
67#include <stdio.h> /* for FILE* */
68
69#if defined(_BSD_WCHAR_T_) && !defined(__cplusplus)
70typedef	_BSD_WCHAR_T_	wchar_t;
71#undef	_BSD_WCHAR_T_
72#endif
73
74#ifdef	_BSD_MBSTATE_T_
75typedef	_BSD_MBSTATE_T_	mbstate_t;
76#undef	_BSD_MBSTATE_T_
77#endif
78
79#ifdef	_BSD_WINT_T_
80typedef	_BSD_WINT_T_	wint_t;
81#undef	_BSD_WINT_T_
82#endif
83
84#ifdef	_BSD_SIZE_T_
85typedef	_BSD_SIZE_T_	size_t;
86#undef	_BSD_SIZE_T_
87#endif
88
89#if defined(_POSIX_C_SOURCE)
90#ifndef __VA_LIST_DECLARED
91typedef __va_list va_list;
92#define __VA_LIST_DECLARED
93#endif
94#endif
95
96struct tm;
97
98__BEGIN_DECLS
99wint_t	btowc(int);
100size_t	mbrlen(const char * __restrict, size_t, mbstate_t * __restrict);
101size_t	mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
102	    mbstate_t * __restrict);
103int	mbsinit(const mbstate_t *);
104size_t	mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
105	    mbstate_t * __restrict);
106size_t	wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
107wchar_t	*wcscat(wchar_t * __restrict, const wchar_t * __restrict);
108wchar_t	*wcschr(const wchar_t *, wchar_t);
109int	wcscmp(const wchar_t *, const wchar_t *);
110int	wcscoll(const wchar_t *, const wchar_t *);
111wchar_t	*wcscpy(wchar_t * __restrict, const wchar_t * __restrict);
112size_t	wcscspn(const wchar_t *, const wchar_t *);
113size_t	wcsftime(wchar_t * __restrict, size_t, const wchar_t * __restrict,
114	    const struct tm * __restrict);
115size_t	wcslen(const wchar_t *);
116wchar_t	*wcsncat(wchar_t * __restrict, const wchar_t * __restrict, size_t);
117int	wcsncmp(const wchar_t *, const wchar_t *, size_t);
118wchar_t	*wcsncpy(wchar_t * __restrict , const wchar_t * __restrict, size_t);
119size_t	wcsnlen(const wchar_t *, size_t);
120wchar_t	*wcspbrk(const wchar_t *, const wchar_t *);
121wchar_t	*wcsrchr(const wchar_t *, wchar_t);
122size_t	wcsrtombs(char * __restrict, const wchar_t ** __restrict, size_t,
123	    mbstate_t * __restrict);
124size_t	wcsspn(const wchar_t *, const wchar_t *);
125wchar_t	*wcsstr(const wchar_t *, const wchar_t *);
126wchar_t *wcstok(wchar_t * __restrict, const wchar_t * __restrict,
127		     wchar_t ** __restrict);
128size_t	wcsxfrm(wchar_t *, const wchar_t *, size_t);
129wchar_t	*wcswcs(const wchar_t *, const wchar_t *);
130wchar_t	*wmemchr(const wchar_t *, wchar_t, size_t);
131int	wmemcmp(const wchar_t *, const wchar_t *, size_t);
132wchar_t	*wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t);
133wchar_t	*wmempcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t);
134wchar_t	*wmemmove(wchar_t *, const wchar_t *, size_t);
135wchar_t	*wmemset(wchar_t *, wchar_t, size_t);
136
137#if defined(_NETBSD_SOURCE)
138size_t	wcslcat(wchar_t *, const wchar_t *, size_t);
139size_t	wcslcpy(wchar_t *, const wchar_t *, size_t);
140#endif
141
142#if defined(_NETBSD_SOURCE) || \
143    (_POSIX_C_SOURCE - 0 >= 200112L) || (_XOPEN_SOURCE - 0) >= 600
144int	wcswidth(const wchar_t *, size_t);
145int	wcwidth(wchar_t);
146#endif
147
148int	wctob(wint_t);
149unsigned long int wcstoul(const wchar_t * __restrict,
150	wchar_t ** __restrict, int);
151long int wcstol(const wchar_t * __restrict,
152	wchar_t ** __restrict, int);
153double wcstod(const wchar_t * __restrict, wchar_t ** __restrict);
154
155#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
156    (__cplusplus - 0) >= 201103L || defined(_NETBSD_SOURCE) || \
157    (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600
158float wcstof(const wchar_t * __restrict, wchar_t ** __restrict);
159long double wcstold(const wchar_t * __restrict, wchar_t ** __restrict);
160
161/* LONGLONG */
162long long int wcstoll(const wchar_t * __restrict,
163	wchar_t ** __restrict, int);
164/* LONGLONG */
165unsigned long long int wcstoull(const wchar_t * __restrict,
166	wchar_t ** __restrict, int);
167#endif
168
169#if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \
170    defined(_NETBSD_SOURCE)
171FILE	*open_wmemstream(wchar_t **, size_t *);
172#endif
173
174wint_t ungetwc(wint_t, FILE *);
175wint_t fgetwc(FILE *);
176wchar_t *fgetws(wchar_t * __restrict, int, FILE * __restrict);
177wint_t getwc(FILE *);
178wint_t getwchar(void);
179wint_t fputwc(wchar_t, FILE *);
180int fputws(const wchar_t * __restrict, FILE * __restrict);
181wint_t putwc(wchar_t, FILE *);
182wint_t putwchar(wchar_t);
183
184int fwide(FILE *, int);
185
186wchar_t	*fgetwln(FILE * __restrict, size_t * __restrict);
187int fwprintf(FILE * __restrict, const wchar_t * __restrict, ...);
188int fwscanf(FILE * __restrict, const wchar_t * __restrict, ...);
189int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ...);
190int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...);
191int vfwprintf(FILE * __restrict, const wchar_t * __restrict, __va_list);
192int vswprintf(wchar_t * __restrict, size_t, const wchar_t * __restrict,
193    __va_list);
194int vwprintf(const wchar_t * __restrict, __va_list);
195int wprintf(const wchar_t * __restrict, ...);
196int wscanf(const wchar_t * __restrict, ...);
197#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) > 199901L || \
198    (__cplusplus - 0) >= 201103L || defined(_NETBSD_SOURCE) || \
199    (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600
200int vfwscanf(FILE * __restrict, const wchar_t * __restrict, __va_list);
201int vswscanf(const wchar_t * __restrict, const wchar_t * __restrict,
202    __va_list);
203int vwscanf(const wchar_t * __restrict, __va_list);
204#endif
205#if defined(_NETBSD_SOURCE)
206struct tinfo;
207int t_putws(struct tinfo *, const wchar_t *, int, void (*)(wchar_t, void *),
208    void *);
209wchar_t *wcsdup (const wchar_t *);
210int wcsncasecmp (const wchar_t *, const wchar_t *, size_t);
211int wcscasecmp(const wchar_t *, const wchar_t *);
212#endif
213__END_DECLS
214
215#ifndef WEOF
216#define	WEOF 	((wint_t)-1)
217#endif
218
219#define getwc(f) fgetwc(f)
220#define getwchar() getwc(stdin)
221#define putwc(wc, f) fputwc((wc), (f))
222#define putwchar(wc) putwc((wc), stdout)
223
224#if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
225#  ifndef __LOCALE_T_DECLARED
226typedef struct _locale		*locale_t;
227#  define __LOCALE_T_DECLARED
228#  endif
229__BEGIN_DECLS
230size_t	mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
231	    size_t, mbstate_t * __restrict);
232size_t	wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t,
233	    size_t, mbstate_t * __restrict);
234
235int	wcscoll_l(const wchar_t *, const wchar_t *, locale_t);
236size_t	wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t);
237int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t);
238int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t);
239
240size_t	wcsftime_l(wchar_t * __restrict, size_t, const wchar_t * __restrict,
241	    const struct tm * __restrict, locale_t);
242
243float wcstof_l(const wchar_t * __restrict, wchar_t ** __restrict, locale_t);
244double wcstod_l(const wchar_t * __restrict, wchar_t ** __restrict, locale_t);
245long double wcstold_l(const wchar_t * __restrict, wchar_t ** __restrict,
246    locale_t);
247long int wcstol_l(const wchar_t * __restrict, wchar_t ** __restrict, int,
248		  locale_t);
249unsigned long int wcstoul_l(const wchar_t * __restrict,
250	wchar_t ** __restrict, int, locale_t);
251/* LONGLONG */
252long long int wcstoll_l(const wchar_t * __restrict, wchar_t ** __restrict, int,
253			locale_t);
254/* LONGLONG */
255unsigned long long int wcstoull_l(const wchar_t * __restrict,
256				  wchar_t ** __restrict, int, locale_t);
257int	wcwidth_l(wchar_t, locale_t);
258int	wcswidth_l(const wchar_t *, size_t, locale_t);
259__END_DECLS
260#endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
261
262#if defined(_NETBSD_SOURCE)
263__BEGIN_DECLS
264wint_t	btowc_l(int, locale_t);
265size_t	mbrlen_l(const char * __restrict, size_t, mbstate_t * __restrict,
266		locale_t);
267size_t	mbrtowc_l(wchar_t * __restrict, const char * __restrict, size_t,
268	    mbstate_t * __restrict, locale_t);
269int	mbsinit_l(const mbstate_t *, locale_t);
270size_t	mbsrtowcs_l(wchar_t * __restrict, const char ** __restrict, size_t,
271	    mbstate_t * __restrict, locale_t);
272size_t	mbsnrtowcs_l(wchar_t * __restrict, const char ** __restrict, size_t,
273	    size_t, mbstate_t * __restrict, locale_t);
274size_t	wcrtomb_l(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
275size_t	wcsrtombs_l(char * __restrict, const wchar_t ** __restrict, size_t,
276	    mbstate_t * __restrict, locale_t);
277size_t	wcsnrtombs_l(char * __restrict, const wchar_t ** __restrict, size_t,
278	    size_t, mbstate_t * __restrict, locale_t);
279int	wctob_l(wint_t, locale_t);
280
281int fwprintf_l(FILE * __restrict, locale_t, const wchar_t * __restrict, ...);
282int swprintf_l(wchar_t * __restrict, size_t n, locale_t,
283    const wchar_t * __restrict, ...);
284int vfwprintf_l(FILE * __restrict, locale_t,
285    const wchar_t * __restrict, __va_list);
286int vswprintf_l(wchar_t * __restrict, size_t, locale_t,
287    const wchar_t * __restrict, __va_list);
288int vwprintf_l(locale_t, const wchar_t * __restrict, __va_list);
289int wprintf_l(locale_t, const wchar_t * __restrict, ...);
290
291int fwscanf_l(FILE * __restrict, locale_t, const wchar_t * __restrict, ...);
292int swscanf_l(const wchar_t * __restrict, locale_t, const wchar_t *
293    __restrict, ...);
294int wscanf_l(locale_t, const wchar_t * __restrict, ...);
295int vfwscanf_l(FILE * __restrict, locale_t, const wchar_t * __restrict,
296    __va_list);
297int vswscanf_l(const wchar_t * __restrict, locale_t, const wchar_t * __restrict,
298    __va_list);
299int vwscanf_l(locale_t, const wchar_t * __restrict, __va_list);
300__END_DECLS
301#endif /* _NETBSD_SOURCE */
302
303#endif /* !_WCHAR_H_ */
304