2 * This code was written by Rich Felker in 2010; no copyright is claimed.
3 * This code is in the public domain. Attribution is appreciated but
11 size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t n, mbstate_t *restrict st)
13 static unsigned internal_state;
15 const unsigned char *s = (const void *)src;
18 if (!st) st = (void *)&internal_state;
24 } else if (!wc) wc = (void *)&wc;
28 if (*s < 0x80) return !!(*wc = *s);
29 if (*s-SA > SB-SA) goto ilseq;
30 c = bittab[*s++-SA]; n--;
34 if (OOB(c,*s)) goto ilseq;
36 c = c<<6 | *s++-0x80; n--;
43 if (*s-0x80u >= 0x40) goto ilseq;