mbstate_t state = { 0 };
mbstate_t state;
int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,	     char *mbstr, int mblen, char *defchr, int *defused,	     struct unicode_data *ucsdata){    /* FIXME: we should remove the defused param completely... */    if (defused)	*defused = 0;    if (codepage == DEFAULT_CODEPAGE) {	char output[MB_LEN_MAX];	mbstate_t state = { 0 };	int n = 0;	setlocale(LC_CTYPE, "");	while (wclen > 0) {	    int i = wcrtomb(output, wcstr[0], &state);	    if (i == (size_t)-1 || i > n - mblen)		break;	    memcpy(mbstr+n, output, i);	    n += i;	    wcstr++;	    wclen--;	}	setlocale(LC_CTYPE, "C");	return n;    } else if (codepage == CS_NONE) {	int n = 0;	while (wclen > 0 && n < mblen) {	    if (*wcstr >= 0xD800 && *wcstr < 0xD900)		mbstr[n++] = (*wcstr & 0xFF);	    else if (defchr)		mbstr[n++] = *defchr;	    wcstr++;	    wclen--;	}	return n;    } else {	return charset_from_unicode(&wcstr, &wclen, mbstr, mblen, codepage,				    NULL, defchr?defchr:NULL, defchr?1:0);    }}