Commit 7d77d77d authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

mbtowc returns -1 if we can't find a valid multibyte char in the non

NULL source string.
parent 6a7d463c
......@@ -588,16 +588,21 @@ unsigned char* _mbstok(unsigned char *str, const unsigned char *delim)
*/
int MSVCRT_mbtowc(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n)
{
if(n <= 0 || !str)
return 0;
if(!MultiByteToWideChar(CP_ACP, 0, str, n, dst, 1))
return 0;
/* return the number of bytes from src that have been used */
if(!*str)
return 0;
if(n >= 2 && MSVCRT_isleadbyte(*str) && str[1])
return 2;
return 1;
/* temp var needed because MultiByteToWideChar wants non NULL destination */
MSVCRT_wchar_t tmpdst = '\0';
if(n <= 0 || !str)
return 0;
if(!MultiByteToWideChar(CP_ACP, 0, str, n, &tmpdst, 1))
return -1;
if(dst)
*dst = tmpdst;
/* return the number of bytes from src that have been used */
if(!*str)
return 0;
if(n >= 2 && MSVCRT_isleadbyte(*str) && str[1])
return 2;
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