From 6f358ef8675ff7b9c3101653e4dbc97532ada593 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Mon, 24 May 2010 10:03:55 +0200 Subject: [PATCH] msvcrt: Fix wcstombs_l implementation. --- dlls/msvcrt/wcs.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index 79be91a0eca..c26809c7b6f 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -240,26 +240,34 @@ MSVCRT_size_t CDECL MSVCRT__wcstombs_l(char *mbstr, const MSVCRT_wchar_t *wcstr, MSVCRT_size_t count, MSVCRT__locale_t locale) { char default_char = '\0'; - MSVCRT_size_t tmp; + MSVCRT_size_t tmp = 0; BOOL used_default; if(!locale) locale = get_locale(); - /* FIXME: Use wcslen here */ - tmp = strlenW(wcstr); - if(tmp>count && mbstr) - tmp = count; + if(!mbstr) + return WideCharToMultiByte(locale->locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS, + wcstr, -1, NULL, 0, &default_char, &used_default)-1; - tmp = WideCharToMultiByte(locale->locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS, - wcstr, tmp, mbstr, count, &default_char, &used_default); + while(*wcstr) { + char buf[3]; + MSVCRT_size_t i, size; - if(used_default) - return -1; + size = WideCharToMultiByte(locale->locinfo->lc_codepage, WC_NO_BEST_FIT_CHARS, + wcstr, 1, buf, 3, &default_char, &used_default); + if(used_default) + return -1; + if(tmp+size > count) + return tmp; - if(tmp