36 _Static_assert(
sizeof(L
"äß")==
sizeof(U
"äß"),
"we need to wchar_t to represend unicode for this to work");
39 unsigned char p00_bytes[
sizeof(mbstate_t)];
44 size_t mbrtoc16(
char16_t * restrict _pc16,
45 const char * restrict _s,
size_t _n,
46 mbstate_t * restrict _ps) {
47 static union p00_mbstate p00_state = { .p00_bytes = { 0 }, };
48 if (!_ps) _ps = &p00_state.p00_state;
55 # if WCHAR_MAX > 0xFFFF
56 mbstate_t p00_st = *_ps;
57 size_t p00_ret = mbrtowc(&p00_wc, _s, _n, &p00_st);
58 if (p00_wc > 0xFFFF)
return -1;
61 size_t p00_ret = mbrtowc(&p00_wc, _s, _n, _ps);
63 if (_pc16 && (p00_ret <= _n)) *_pc16 = p00_wc;
68 size_t c16rtomb(
char * restrict _s,
char16_t _c16,
69 mbstate_t * restrict _ps) {
70 static union p00_mbstate p00_state = { .p00_bytes = { 0 }, };
71 if (!_ps) _ps = &p00_state.p00_state;
72 return wcrtomb(_s, _c16, _ps);
76 size_t mbrtoc32(
char32_t * restrict _pc32,
77 const char * restrict _s,
size_t _n,
78 mbstate_t * restrict _ps) {
79 static union p00_mbstate p00_state = { .p00_bytes = { 0 }, };
80 if (!_ps) _ps = &p00_state.p00_state;
87 # if WCHAR_MAX > 0xFFFFFFFF
88 mbstate_t p00_st = *_ps;
89 size_t p00_ret = mbrtowc(&p00_wc, _s, _n, &p00_st);
90 if (p00_wc > 0xFFFFFFFF)
return -1;
93 size_t p00_ret = mbrtowc(&p00_wc, _s, _n, _ps);
95 if (_pc32 && (p00_ret <= _n)) *_pc32 = p00_wc;
100 size_t c32rtomb(
char * restrict _s,
char32_t _c32,
101 mbstate_t * restrict _ps) {
102 if (_s && (_c32 > WCHAR_MAX)) {
106 static union p00_mbstate p00_state = { .p00_bytes = { 0 }, };
107 if (!_ps) _ps = &p00_state.p00_state;
108 return wcrtomb(_s, _c32, _ps);