xref: /haiku/headers/posix/wchar.h (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
1 /*
2  * Copyright 2008-2012 Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _WCHAR_H
6 #define _WCHAR_H
7 
8 
9 #include <limits.h>
10 #include <locale_t.h>
11 #include <stddef.h>
12 #include <stdio.h>
13 #include <time.h>
14 
15 
16 /* stddef.h is not supposed to define wint_t, but gcc 2.95.3's one does.
17  * In all other cases we will do that. */
18 #ifndef _WINT_T
19 #define _WINT_T
20 
21 #ifndef __WINT_TYPE__
22 #define __WINT_TYPE__ unsigned int
23 #endif
24 
25 typedef __WINT_TYPE__ wint_t;
26 
27 #endif	/* _WINT_T */
28 
29 typedef int wctype_t;
30 
31 typedef struct {
32 	void* converter;
33 	char charset[64];
34 	unsigned int count;
35 	char data[1024 + 8];	/* 1024 bytes for data, 8 for alignment space */
36 } mbstate_t;
37 
38 
39 #define WEOF		((wint_t)(-1))
40 
41 #define WCHAR_MIN	0x00000000UL
42 #define WCHAR_MAX	0x7FFFFFFFUL
43 
44 /*
45  * Haiku is always using UTF32 in wchars, other encodings can be handled
46  * by converting to/from wchar by means of mbrtowc() or wcrtomb().
47  */
48 
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 extern wint_t	btowc(int);
55 
56 extern wint_t	fgetwc(FILE *stream);
57 extern wchar_t	*fgetws(wchar_t *dest, int destLength, FILE *stream);
58 extern wint_t	fputwc(wchar_t wc, FILE *stream);
59 extern int		fputws(const wchar_t *wcs, FILE *stream);
60 extern int		fwide(FILE *stream, int mode);
61 extern int		fwprintf(FILE *stream, const wchar_t *format, ...);
62 extern int		fwscanf(FILE *stream, const wchar_t *format, ...);
63 extern wint_t	getwc(FILE *stream);
64 extern wint_t	getwchar(void);
65 
66 extern size_t 	mbrlen(const char *s, size_t n, mbstate_t *mbState);
67 extern size_t 	mbrtowc(wchar_t *dest, const char *src, size_t srcLength,
68 					mbstate_t *mbState);
69 extern int		mbsinit(const mbstate_t *mbState);
70 extern size_t	mbsnrtowcs(wchar_t *dest, const char **src, size_t srcLength,
71 					size_t destLength, mbstate_t *mbState);
72 extern size_t	mbsrtowcs(wchar_t *dest, const char **src, size_t destLength,
73 					mbstate_t *mbState);
74 
75 extern wint_t	putwc(wchar_t wc, FILE *stream);
76 extern wint_t	putwchar(wchar_t wc);
77 
78 extern int		swprintf(wchar_t *dest, size_t destLength,
79 					const wchar_t *format, ...);
80 extern int		swscanf(const wchar_t *wcs, const wchar_t *format, ...);
81 
82 extern wint_t	ungetwc(wint_t wc, FILE *stream);
83 
84 extern int		vfwprintf(FILE *stream, const wchar_t *format, va_list arg);
85 extern int		vfwscanf(FILE *stream, const wchar_t *format, va_list arg);
86 extern int		vswprintf(wchar_t *dest, size_t destLength,
87 					const wchar_t *format, va_list arg);
88 extern int		vswscanf(const wchar_t *wcs, const wchar_t *format,
89 					va_list arg);
90 extern int		vwprintf(const wchar_t *format, va_list arg);
91 extern int		vwscanf(const wchar_t *format, va_list arg);
92 
93 extern wchar_t	*wcpcpy(wchar_t *dest, const wchar_t *src);
94 extern wchar_t	*wcpncpy(wchar_t *dest, const wchar_t *src, size_t srcLength);
95 extern size_t   wcrtomb(char *dest, wchar_t wc, mbstate_t *mbState);
96 extern int		wcscasecmp(const wchar_t *wcs1, const wchar_t *wcs2);
97 extern int		wcscasecmp_l(const wchar_t *wcs1, const wchar_t *wcs2, locale_t locale);
98 extern wchar_t	*wcscat(wchar_t *dest, const wchar_t *src);
99 extern wchar_t	*wcschr(const wchar_t *wcs, wchar_t wc);
100 #ifdef _DEFAULT_SOURCE
101 extern wchar_t	*wcschrnul(const wchar_t *wcs, wchar_t wc);
102 #endif
103 extern int      wcscmp(const wchar_t *wcs1, const wchar_t *wcs2);
104 extern int      wcscoll(const wchar_t *wcs1, const wchar_t *wcs2);
105 extern int		wcscoll_l(const wchar_t *wcs1, const wchar_t *wcs2, locale_t locale);
106 extern wchar_t	*wcscpy(wchar_t *dest, const wchar_t *src);
107 extern size_t	wcscspn(const wchar_t *wcs, const wchar_t *reject);
108 extern wchar_t	*wcsdup(const wchar_t *wcs);
109 extern size_t	wcsftime(wchar_t *dest, size_t destLength,
110 					const wchar_t *format, const struct tm *timeptr);
111 extern size_t	wcslcat(wchar_t *dest, const wchar_t *src, size_t maxLength);
112 extern size_t	wcslcpy(wchar_t *dest, const wchar_t *src, size_t maxLength);
113 extern size_t	wcslen(const wchar_t *wcs);
114 extern int		wcsncasecmp(const wchar_t *wcs1, const wchar_t *wcs2,
115 					size_t maxLength);
116 extern int		wcsncasecmp_l(const wchar_t *wcs1, const wchar_t *wcs2,
117 					size_t maxLength, locale_t locale);
118 extern wchar_t 	*wcsncat(wchar_t *dest, const wchar_t *src, size_t srcLength);
119 extern int		wcsncmp(const wchar_t *wcs1, const wchar_t *wcs2,
120 					size_t length);
121 extern wchar_t	*wcsncpy(wchar_t *dest, const wchar_t *src, size_t srcLength);
122 extern size_t	wcsnlen(const wchar_t *wcs, size_t maxLength);
123 extern size_t   wcsnrtombs(char *dest, const wchar_t **src, size_t srcLength,
124 					size_t destLength, mbstate_t *mbState);
125 extern wchar_t	*wcspbrk(const wchar_t *wcs, const wchar_t *accept);
126 extern wchar_t	*wcsrchr(const wchar_t *wcs, wchar_t wc);
127 extern size_t   wcsrtombs(char *dest, const wchar_t **src, size_t destLength,
128 					mbstate_t *mbState);
129 extern size_t	wcsspn(const wchar_t *wcs, const wchar_t *accept);
130 extern wchar_t	*wcsstr(const wchar_t *haystack, const wchar_t *needle);
131 extern double	wcstod(const wchar_t *wcs, wchar_t **endPtr);
132 extern float	wcstof(const wchar_t *wcs, wchar_t **endPtr);
133 extern wchar_t	*wcstok(wchar_t *wcs1, const wchar_t *wcs2, wchar_t **ptr);
134 extern long		wcstol(const wchar_t *wcs, wchar_t **endPtr, int base);
135 extern long double	wcstold(const wchar_t *wcs, wchar_t **endPtr);
136 extern long long	wcstoll(const wchar_t *wcs, wchar_t **endPtr, int base);
137 extern unsigned long	wcstoul(const wchar_t *wcs, wchar_t **endPtr,
138 							int base);
139 extern unsigned long long	wcstoull(const wchar_t *wcs, wchar_t **endPtr,
140 								int base);
141 extern wchar_t	*wcswcs(const wchar_t *haystack, const wchar_t *needle);
142 extern int		wcswidth(const wchar_t *wcs, size_t length);
143 extern size_t	wcsxfrm(wchar_t *dest, const wchar_t *src, size_t destLength);
144 extern size_t	wcsxfrm_l(wchar_t *dest, const wchar_t *src, size_t destLength,
145 					locale_t locale);
146 extern int		wctob(wint_t wc);
147 extern int		wcwidth(wchar_t wc);
148 extern wchar_t	*wmemchr(const wchar_t *wcs, wchar_t wc, size_t n);
149 extern int		wmemcmp(const wchar_t *wcs1, const wchar_t *wcs2, size_t n);
150 extern wchar_t	*wmemcpy(wchar_t *dest, const wchar_t *src, size_t n);
151 extern wchar_t	*wmemmove(wchar_t *dest, const wchar_t *src, size_t n);
152 #ifdef _DEFAULT_SOURCE
153 extern wchar_t	*wmempcpy(wchar_t *dest, const wchar_t *src, size_t n);
154 #endif
155 extern wchar_t	*wmemset(wchar_t *dest, wchar_t wc, size_t n);
156 
157 extern int		wprintf(const wchar_t *format, ...);
158 extern int		wscanf(const wchar_t *format, ...);
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif /* _WCHAR_H */
165