mirror of
https://github.com/reactos/reactos.git
synced 2024-11-01 04:11:30 +00:00
d8eeb31b8a
This is a partial sync of the CRT library with wcsrtombs_l and _mbstowcs_l functions from WINE. The _wctomb_s_l implementation of WINE which is used by _wctomb_s, _wctomb_l and wctomb brings failed results of the wctomb unit testcase and at the same time it crashes the whole testcase after. Therefore I will not address the wctomb function for the moment being.
67 lines
1.5 KiB
C
67 lines
1.5 KiB
C
#include <precomp.h>
|
|
|
|
/*********************************************************************
|
|
* _mbstowcs_l (MSVCRT.@)
|
|
*/
|
|
size_t CDECL _mbstowcs_l(wchar_t *wcstr, const char *mbstr,
|
|
size_t count, _locale_t locale)
|
|
{
|
|
MSVCRT_pthreadlocinfo locinfo;
|
|
size_t i, size;
|
|
|
|
if(!mbstr) {
|
|
_set_errno(EINVAL);
|
|
return -1;
|
|
}
|
|
|
|
if(!locale)
|
|
locinfo = get_locinfo();
|
|
else
|
|
locinfo = ((MSVCRT__locale_t)locale)->locinfo;
|
|
|
|
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;
|
|
}
|
|
|
|
/* Ignore count parameter */
|
|
if(!wcstr)
|
|
return MultiByteToWideChar(locinfo->lc_codepage, 0, mbstr, -1, NULL, 0)-1;
|
|
|
|
for(i=0, size=0; i<count; i++) {
|
|
if(mbstr[size] == '\0')
|
|
break;
|
|
|
|
size += (_isleadbyte_l((unsigned char)mbstr[size], locale) ? 2 : 1);
|
|
}
|
|
|
|
if(size) {
|
|
size = MultiByteToWideChar(locinfo->lc_codepage, 0,
|
|
mbstr, size, wcstr, count);
|
|
if(!size) {
|
|
if(count) wcstr[0] = '\0';
|
|
_set_errno(EILSEQ);
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
if(size<count)
|
|
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);
|
|
}
|