Created
April 10, 2012 17:55
-
-
Save Veejay/2353248 to your computer and use it in GitHub Desktop.
pike.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int | |
mbtowc(wchar_t *p, char *s, size_t n) | |
{ | |
long l; | |
int c0, c, nc; | |
Tab *t; | |
if(s == 0) | |
return 0; | |
nc = 0; | |
if(n <= nc) | |
return -1; | |
c0 = *s & 0xff; | |
l = c0; | |
for(t=tab; t->cmask; t++) { | |
nc++; | |
if((c0 & t->cmask) == t->cval) { | |
l &= t->lmask; | |
if(l < t->lval) | |
return -1; | |
*p = l; | |
return nc; | |
} | |
if(n <= nc) | |
return -1; | |
s++; | |
c = (*s ^ 0x80) & 0xFF; | |
if(c & 0xC0) | |
return -1; | |
l = (l<<6) | c; | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment