Piotr Caban : msvcrt: Fix mbstowcs_l implementation.

Alexandre Julliard julliard at winehq.org
Mon May 24 11:30:49 CDT 2010


Module: wine
Branch: master
Commit: 2ca3b9e0162fac9d2a09c8d92df08034c4cb6b44
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2ca3b9e0162fac9d2a09c8d92df08034c4cb6b44

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Sat May 22 22:24:40 2010 +0200

msvcrt: Fix mbstowcs_l implementation.

---

 dlls/msvcrt/mbcs.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index 837ac02..8fca06d 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -1725,22 +1725,29 @@ MSVCRT_size_t CDECL _mbstrlen(const char* str)
 MSVCRT_size_t CDECL MSVCRT__mbstowcs_l(MSVCRT_wchar_t *wcstr, const char *mbstr,
         MSVCRT_size_t count, MSVCRT__locale_t locale)
 {
-    MSVCRT_size_t tmp;
+    MSVCRT_size_t i, size;
 
     if(!locale)
         locale = get_locale();
 
-    tmp = _mbstrlen_l(mbstr, locale);
-    if(tmp>count && wcstr)
-        tmp = count;
+    /* Ignore count parameter */
+    if(!wcstr)
+        return MultiByteToWideChar(locale->locinfo->lc_codepage, 0, mbstr, -1, NULL, 0)-1;
 
-    tmp = MultiByteToWideChar(locale->locinfo->lc_codepage, 0,
-            mbstr, tmp, wcstr, count);
+    for(i=0, size=0; i<count; i++) {
+        if(mbstr[size] == '\0')
+            break;
+
+        size += (MSVCRT_isleadbyte(mbstr[size]) ? 2 : 1);
+    }
+
+    size = MultiByteToWideChar(locale->locinfo->lc_codepage, 0,
+            mbstr, size, wcstr, count);
 
-    if(tmp<count && wcstr)
-        wcstr[tmp] = '\0';
+    if(size<count && wcstr)
+        wcstr[size] = '\0';
 
-    return tmp;
+    return size;
 }
 
 /*********************************************************************




More information about the wine-cvs mailing list