2007-03-14 20:24:57 +00:00
|
|
|
#include <precomp.h>
|
|
|
|
|
2015-10-25 08:36:14 +00:00
|
|
|
/*********************************************************************
|
2020-05-01 16:36:19 +00:00
|
|
|
* _mbstowcs_l (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2015-10-25 08:36:14 +00:00
|
|
|
size_t CDECL _mbstowcs_l(wchar_t *wcstr, const char *mbstr,
|
|
|
|
size_t count, _locale_t locale)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2015-10-25 08:36:14 +00:00
|
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
|
|
size_t i, size;
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2020-05-01 16:36:19 +00:00
|
|
|
if(!mbstr) {
|
|
|
|
_set_errno(EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-10-25 08:36:14 +00:00
|
|
|
if(!locale)
|
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = ((MSVCRT__locale_t)locale)->locinfo;
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2020-05-01 16:36:19 +00:00
|
|
|
if(!locinfo->lc_codepage) {
|
|
|
|
if(!wcstr)
|
|
|
|
return strlen(mbstr);
|
|
|
|
|
|
|
|
for(i=0; i<count; i++) {
|
|
|
|
wcstr[i] = (unsigned char)mbstr[i];
|
|
|
|
if(!wcstr[i]) break;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2015-10-25 08:36:14 +00:00
|
|
|
/* Ignore count parameter */
|
|
|
|
if(!wcstr)
|
|
|
|
return MultiByteToWideChar(locinfo->lc_codepage, 0, mbstr, -1, NULL, 0)-1;
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2015-10-25 08:36:14 +00:00
|
|
|
for(i=0, size=0; i<count; i++) {
|
|
|
|
if(mbstr[size] == '\0')
|
|
|
|
break;
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2015-10-25 08:36:14 +00:00
|
|
|
size += (_isleadbyte_l((unsigned char)mbstr[size], locale) ? 2 : 1);
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 16:36:19 +00:00
|
|
|
if(size) {
|
|
|
|
size = MultiByteToWideChar(locinfo->lc_codepage, 0,
|
|
|
|
mbstr, size, wcstr, count);
|
|
|
|
if(!size) {
|
|
|
|
if(count) wcstr[0] = '\0';
|
|
|
|
_set_errno(EILSEQ);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2015-10-25 08:36:14 +00:00
|
|
|
|
2020-05-01 16:36:19 +00:00
|
|
|
if(size<count)
|
2015-10-25 08:36:14 +00:00
|
|
|
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);
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|