mbstate_t state = { 0 };
mbstate_t state;
int mb_to_wc(int codepage, int flags, char *mbstr, int mblen,	     wchar_t *wcstr, int wclen){    if (codepage == DEFAULT_CODEPAGE) {	int n = 0;	mbstate_t state = { 0 };	setlocale(LC_CTYPE, "");	while (mblen > 0) {	    size_t i = mbrtowc(wcstr+n, mbstr, (size_t)mblen, &state);	    if (i == (size_t)-1 || i == (size_t)-2)		break;	    n++;	    mbstr += i;	    mblen -= i;	}	setlocale(LC_CTYPE, "C");	return n;    } else if (codepage == CS_NONE) {	int n = 0;	while (mblen > 0) {	    wcstr[n] = 0xD800 | (mbstr[0] & 0xFF);	    n++;	    mbstr++;	    mblen--;	}	return n;    } else	return charset_to_unicode(&mbstr, &mblen, wcstr, wclen, codepage,				  NULL, NULL, 0);}