From 7d77d77d7184d97be54f67d11dac432a21317425 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Thu, 17 Apr 2003 02:15:03 +0000 Subject: [PATCH] mbtowc returns -1 if we can't find a valid multibyte char in the non NULL source string. --- dlls/msvcrt/mbcs.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c index 2421011eb5c..b8ee9d46da1 100644 --- a/dlls/msvcrt/mbcs.c +++ b/dlls/msvcrt/mbcs.c @@ -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; } /********************************************************************* -- 2.11.4.GIT