mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 17:56:00 +00:00
[CRT]
Import _mbstowcs_l() from Wine and call it in mbstowcs(). This fixes crashes when calling the msvcrt, crtdll implementation of mbstowcs() with no output string. Thus, it fixes a few crashing apitests The NTDLL version is still broken in some way, need to investigate why. CORE-10390 #resolve #comment Fixed with 69682. Thanks for the report! svn path=/trunk/; revision=69682
This commit is contained in:
parent
54af95dc46
commit
d9674b27cf
1 changed files with 34 additions and 19 deletions
|
@ -1,28 +1,43 @@
|
||||||
#include <precomp.h>
|
#include <precomp.h>
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* _mbstowcs_l
|
||||||
|
*/
|
||||||
|
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(!locale)
|
||||||
|
locinfo = get_locinfo();
|
||||||
|
else
|
||||||
|
locinfo = ((MSVCRT__locale_t)locale)->locinfo;
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
size = MultiByteToWideChar(locinfo->lc_codepage, 0,
|
||||||
|
mbstr, size, wcstr, count);
|
||||||
|
|
||||||
|
if(size<count && wcstr)
|
||||||
|
wcstr[size] = '\0';
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
size_t mbstowcs (wchar_t *widechar, const char *multibyte, size_t number)
|
size_t mbstowcs (wchar_t *widechar, const char *multibyte, size_t number)
|
||||||
{
|
{
|
||||||
int bytes;
|
return _mbstowcs_l(widechar, multibyte, number, NULL);
|
||||||
size_t n = 0;
|
|
||||||
|
|
||||||
while (n < number) {
|
|
||||||
|
|
||||||
if ((bytes = mbtowc (widechar, multibyte, MB_LEN_MAX)) < 0)
|
|
||||||
return (size_t) -1;
|
|
||||||
|
|
||||||
if (bytes == 0) {
|
|
||||||
*widechar = (wchar_t) '\0';
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
widechar++;
|
|
||||||
multibyte += bytes;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue