6 size_t mbrtowc(wchar_t *restrict wc
, const char *restrict src
, size_t n
, mbstate_t *restrict st
)
8 static unsigned internal_state
;
10 const unsigned char *s
= (const void *)src
;
14 if (!st
) st
= (void *)&internal_state
;
20 } else if (!wc
) wc
= &dummy
;
24 if (*s
< 0x80) return !!(*wc
= *s
);
25 if (MB_CUR_MAX
==1) return (*wc
= CODEUNIT(*s
)), 1;
26 if (*s
-SA
> SB
-SA
) goto ilseq
;
27 c
= bittab
[*s
++-SA
]; n
--;
31 if (OOB(c
,*s
)) goto ilseq
;
33 c
= c
<<6 | *s
++-0x80; n
--;
40 if (*s
-0x80u
>= 0x40) goto ilseq
;