msvcrt: Fix mbtowc behavior for buffers containing more than one character.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Piotr Caban 2016-05-06 22:09:14 +02:00 committed by Alexandre Julliard
parent 8fb1802b9c
commit a36b5f0741
1 changed files with 17 additions and 9 deletions

View File

@ -2157,17 +2157,25 @@ int CDECL MSVCRT_mbtowc_l(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n,
if(n <= 0 || !str)
return 0;
if(!locinfo->lc_codepage)
tmpdst = (unsigned char)*str;
else if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, n, &tmpdst, 1))
return -1;
if(dst)
*dst = tmpdst;
/* return the number of bytes from src that have been used */
if(!*str)
if(!*str) {
if(dst) *dst = 0;
return 0;
if(n >= 2 && MSVCRT__isleadbyte_l((unsigned char)*str, locale) && str[1])
}
if(!locinfo->lc_codepage) {
if(dst) *dst = (unsigned char)*str;
return 1;
}
if(n>=2 && MSVCRT__isleadbyte_l((unsigned char)*str, locale)) {
if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 2, &tmpdst, 1))
return -1;
if(dst) *dst = tmpdst;
return 2;
}
if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 1, &tmpdst, 1))
return -1;
if(dst) *dst = tmpdst;
return 1;
}