xref: /haiku/headers/posix/uchar.h (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
1 /*
2  * Copyright 2018-2020 Haiku, Inc. All Right Reserved
3  * Distributed under the terms of MIT license.
4  */
5 #ifndef _UCHAR_H
6 #define _UCHAR_H
7 
8 
9 #include <wchar.h>
10 
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 
17 typedef uint_least32_t char32_t;
18 typedef uint_least16_t char16_t;
19 
20 
21 #define __STD_UTF_32__ 1
22 #define __STD_UTF_16__ 1
23 
24 
25 // TODO implement mbrtoc16
26 
27 
28 static __inline size_t
29 c16rtomb(char *dest, char32_t wc, mbstate_t *mbState)
30 {
31 	wchar_t tmp = (wchar_t)wc;
32 	return wcrtomb(dest, tmp, mbState);
33 }
34 
35 
36 static __inline size_t
37 mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState)
38 {
39 	return mbrtowc((wchar_t*)dest, src, srcLength, mbState);
40 }
41 
42 
43 static __inline size_t
44 c32rtomb(char *dest, char32_t wc, mbstate_t *mbState)
45 {
46 	return wcrtomb(dest, (wchar_t)wc, mbState);
47 }
48 
49 
50 #ifdef __cplusplus
51 }
52 #endif
53 #endif /* _UCHAR_H */
54