[CRT]
[reactos.git] / reactos / lib / sdk / crt / stdlib / mbstowcs.c
index ba7e4c1..1fe9917 100644 (file)
@@ -1,28 +1,43 @@
 #include <precomp.h>
 
 #include <precomp.h>
 
-
-/*
- * @implemented
+/*********************************************************************
+ * _mbstowcs_l
  */
  */
-size_t mbstowcs (wchar_t *widechar, const char *multibyte, size_t number)
+size_t CDECL _mbstowcs_l(wchar_t *wcstr, const char *mbstr,
+        size_t count, _locale_t locale)
 {
 {
-    int bytes;
-    size_t n = 0;
+    MSVCRT_pthreadlocinfo locinfo;
+    size_t i, size;
 
 
-    while (n < number) {
+    if(!locale)
+        locinfo = get_locinfo();
+    else
+        locinfo = ((MSVCRT__locale_t)locale)->locinfo;
 
 
-       if ((bytes = mbtowc (widechar, multibyte, MB_LEN_MAX)) < 0)
-           return (size_t) -1;
+    /* Ignore count parameter */
+    if(!wcstr)
+        return MultiByteToWideChar(locinfo->lc_codepage, 0, mbstr, -1, NULL, 0)-1;
 
 
-       if (bytes == 0) {
-           *widechar = (wchar_t) '\0';
-           return n;
-       }
+    for(i=0, size=0; i<count; i++) {
+        if(mbstr[size] == '\0')
+            break;
 
 
-       widechar++;
-       multibyte += bytes;
-       n++;
+        size += (_isleadbyte_l((unsigned char)mbstr[size], locale) ? 2 : 1);
     }
 
     }
 
-    return n;
+    size = MultiByteToWideChar(locinfo->lc_codepage, 0,
+            mbstr, size, wcstr, count);
+
+    if(size<count && wcstr)
+        wcstr[size] = '\0';
+
+    return size;
+}
+
+/*
+ * @implemented
+ */
+size_t mbstowcs (wchar_t *widechar, const char *multibyte, size_t number)
+{
+    return _mbstowcs_l(widechar, multibyte, number, NULL);
 }
 }