Commit a36b5f07 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

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

parent 8fb1802b
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment