6 int mbtowc(wchar_t *restrict wc
, const char *restrict src
, size_t n
)
9 const unsigned char *s
= (const void *)src
;
16 if (*s
< 0x80) return !!(*wc
= *s
);
17 if (MB_CUR_MAX
==1) return (*wc
= CODEUNIT(*s
)), 1;
18 if (*s
-SA
> SB
-SA
) goto ilseq
;
21 /* Avoid excessive checks against n: If shifting the state n-1
22 * times does not clear the high bit, then the value of n is
23 * insufficient to read a character */
24 if (n
<4 && ((c
<<(6*n
-6)) & (1U<<31))) goto ilseq
;
26 if (OOB(c
,*s
)) goto ilseq
;
33 if (*s
-0x80u
>= 0x40) goto ilseq
;
40 if (*s
-0x80u
>= 0x40) goto ilseq
;
41 *wc
= c
<<6 | *s
++-0x80;