[CRT]
authorAmine Khaldi <amine.khaldi@reactos.org>
Sun, 18 May 2014 18:35:45 +0000 (18:35 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 18 May 2014 18:35:45 +0000 (18:35 +0000)
* Import _isleadbyte_l().
* Import _mbtowc_l().
* Import mbtowc() instead of our own.
* Fixes some msvcrt tests.
CORE-8080

svn path=/trunk/; revision=63358

reactos/lib/sdk/crt/stdlib/mbtowc.c
reactos/lib/sdk/crt/string/ctype.c

index 6830367..13366a0 100644 (file)
 
 #include <precomp.h>
 
-
-/*
- * @implemented
+/*********************************************************************
+ *             _mbtowc_l(MSVCRT.@)
  */
-
-int mbtowc (wchar_t *charptr, const char *address, size_t number)
+int CDECL _mbtowc_l(wchar_t *dst, const char* str, size_t n, _locale_t locale)
 {
-    int bytes;
-
-    if (address == 0)
-       return 0;
-
-    if ((bytes = mblen (address, number)) < 0)
-       return bytes;
-
-    if (charptr) {
-       switch (bytes) {
-       case 0:
-           if (number > 0) 
-               *charptr = (wchar_t) '\0';
-           break;
-       case 1:
-           *charptr = (wchar_t) ((unsigned char) address[0]);
-           break;
-       case 2:
-           *charptr = (wchar_t) (((unsigned char) address[0] << 8)
-                                 | (unsigned char) address[1]);
-           break;
-       }
-    }
+    MSVCRT_pthreadlocinfo locinfo;
+    wchar_t tmpdst = '\0';
+
+    if(!locale)
+        locinfo = get_locinfo();
+    else
+        locinfo = (MSVCRT_pthreadlocinfo)(locale->locinfo);
+
+    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)
+        return 0;
+    if(n >= 2 && _isleadbyte_l((unsigned char)*str, locale) && str[1])
+        return 2;
+    return 1;
+}
 
-    return bytes;
+/*********************************************************************
+ *              mbtowc(MSVCRT.@)
+ */
+int CDECL mbtowc(wchar_t *dst, const char* str, size_t n)
+{
+    return _mbtowc_l(dst, str, n, NULL);
 }
index 1dbbee4..bf5d1cd 100644 (file)
@@ -614,6 +614,15 @@ int __cdecl _isctype (int c, int ctypeFlags)
 { 
   return _isctype_l(c, ctypeFlags, NULL);
 }
+
+/*********************************************************************
+ *             _isleadbyte_l (MSVCRT.@)
+ */
+int __cdecl _isleadbyte_l(int c, _locale_t locale)
+{
+  return _isctype_l( c, _LEADBYTE, locale );
+}
+
 #endif /* _LIBCNT_ */
 
 /*