1 #include <precomp.h>
2
3 /*********************************************************************
4 * _mbstowcs_l (MSVCRT.@)
5 */
_mbstowcs_l(wchar_t * wcstr,const char * mbstr,size_t count,_locale_t locale)6 size_t CDECL _mbstowcs_l(wchar_t *wcstr, const char *mbstr,
7 size_t count, _locale_t locale)
8 {
9 MSVCRT_pthreadlocinfo locinfo;
10 size_t i, size;
11
12 if(!mbstr) {
13 _set_errno(EINVAL);
14 return -1;
15 }
16
17 if(!locale)
18 locinfo = get_locinfo();
19 else
20 locinfo = ((MSVCRT__locale_t)locale)->locinfo;
21
22 if(!locinfo->lc_codepage) {
23 if(!wcstr)
24 return strlen(mbstr);
25
26 for(i=0; i<count; i++) {
27 wcstr[i] = (unsigned char)mbstr[i];
28 if(!wcstr[i]) break;
29 }
30 return i;
31 }
32
33 /* Ignore count parameter */
34 if(!wcstr)
35 return MultiByteToWideChar(locinfo->lc_codepage, 0, mbstr, -1, NULL, 0)-1;
36
37 for(i=0, size=0; i<count; i++) {
38 if(mbstr[size] == '\0')
39 break;
40
41 size += (_isleadbyte_l((unsigned char)mbstr[size], locale) ? 2 : 1);
42 }
43
44 if(size) {
45 size = MultiByteToWideChar(locinfo->lc_codepage, 0,
46 mbstr, size, wcstr, count);
47 if(!size) {
48 if(count) wcstr[0] = '\0';
49 _set_errno(EILSEQ);
50 return -1;
51 }
52 }
53
54 if(size<count)
55 wcstr[size] = '\0';
56
57 return size;
58 }
59
60 /*
61 * @implemented
62 */
mbstowcs(wchar_t * widechar,const char * multibyte,size_t number)63 size_t mbstowcs (wchar_t *widechar, const char *multibyte, size_t number)
64 {
65 return _mbstowcs_l(widechar, multibyte, number, NULL);
66 }
67