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;
19 if (!st) st = (void *)&internal_state;
25 } else if (!wc) wc = &dummy;
29 if (*s < 0x80) return !!(*wc = *s);
30 if (*s-SA > SB-SA) goto ilseq;
31 c = bittab[*s++-SA]; n--;
35 if (OOB(c,*s)) goto ilseq;
37 c = c<<6 | *s++-0x80; n--;
44 if (*s-0x80u >= 0x40) goto ilseq;