msvcrt: Added wcstombs_s implementation.

This commit is contained in:
Piotr Caban 2010-04-27 08:42:46 +02:00 committed by Alexandre Julliard
parent 0ec1635172
commit 6c0e61cd65
4 changed files with 82 additions and 6 deletions

View File

@ -1110,7 +1110,7 @@
@ cdecl _wcstoi64_l(wstr ptr long ptr) msvcrt._wcstoi64_l
@ stub _wcstol_l
@ stub _wcstombs_l
@ stub _wcstombs_s_l
@ cdecl _wcstombs_s_l(ptr ptr long wstr long ptr) msvcrt._wcstombs_s_l
@ cdecl _wcstoui64(wstr ptr long) msvcrt._wcstoui64
@ cdecl _wcstoui64_l(wstr ptr long ptr) msvcrt._wcstoui64_l
@ stub _wcstoul_l
@ -1456,7 +1456,7 @@
@ stub wcstok_s
@ cdecl wcstol(wstr ptr long) msvcrt.wcstol
@ cdecl wcstombs(ptr ptr long) msvcrt.wcstombs
@ stub wcstombs_s
@ cdecl wcstombs_s(ptr ptr long wstr long) msvcrt.wcstombs_s
@ cdecl wcstoul(wstr ptr long) msvcrt.wcstoul
@ stub wcsxfrm
@ stub wctob

View File

@ -1097,7 +1097,7 @@
@ cdecl _wcstoi64_l(wstr ptr long ptr) msvcrt._wcstoi64_l
@ stub _wcstol_l
@ stub _wcstombs_l
@ stub _wcstombs_s_l
@ cdecl _wcstombs_s_l(ptr ptr long wstr long ptr) msvcrt._wcstombs_s_l
@ cdecl _wcstoui64(wstr ptr long) msvcrt._wcstoui64
@ cdecl _wcstoui64_l(wstr ptr long ptr) msvcrt._wcstoui64_l
@ stub _wcstoul_l
@ -1440,7 +1440,7 @@
@ stub wcstok_s
@ cdecl wcstol(wstr ptr long) msvcrt.wcstol
@ cdecl wcstombs(ptr ptr long) msvcrt.wcstombs
@ stub wcstombs_s
@ cdecl wcstombs_s(ptr ptr long wstr long) msvcrt.wcstombs_s
@ cdecl wcstoul(wstr ptr long) msvcrt.wcstoul
@ stub wcsxfrm
@ stub wctob

View File

@ -1039,7 +1039,7 @@
@ cdecl _wcstoi64_l(wstr ptr long ptr) MSVCRT__wcstoi64_l
# stub _wcstol_l
# stub _wcstombs_l
# stub _wcstombs_s_l
@ cdecl _wcstombs_s_l(ptr ptr long wstr long ptr) MSVCRT__wcstombs_s_l
@ cdecl _wcstoui64(wstr ptr long) MSVCRT__wcstoui64
@ cdecl _wcstoui64_l(wstr ptr long ptr) MSVCRT__wcstoui64_l
# stub _wcstoul_l
@ -1396,7 +1396,7 @@
# stub wcstok_s
@ cdecl wcstol(wstr ptr long) ntdll.wcstol
@ cdecl wcstombs(ptr ptr long) ntdll.wcstombs
# stub wcstombs_s
@ cdecl wcstombs_s(ptr ptr long wstr long) MSVCRT_wcstombs_s
@ cdecl wcstoul(wstr ptr long) ntdll.wcstoul
@ stub wcsxfrm #(ptr wstr long) MSVCRT_wcsxfrm
# stub wctob

View File

@ -226,6 +226,82 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
return ret;
}
/*********************************************************************
* _wcstombs_s_l (MSVCRT.@)
*/
int CDECL MSVCRT__wcstombs_s_l(MSVCRT_size_t *ret, char *mbstr,
MSVCRT_size_t size, const MSVCRT_wchar_t *wcstr,
MSVCRT_size_t count, MSVCRT__locale_t locale)
{
char default_char = '\0', *p;
int hlp, len;
if(!size)
return 0;
if(!mbstr || !wcstr) {
MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
if(mbstr)
*mbstr = '\0';
*MSVCRT__errno() = MSVCRT_EINVAL;
return MSVCRT_EINVAL;
}
if(!locale)
locale = get_locale();
if(size<=count)
len = size;
else if(count==_TRUNCATE)
len = size-1;
else
len = count;
p = mbstr;
*ret = 0;
while(1) {
if(!len)
break;
if(*wcstr == '\0') {
*p = '\0';
break;
}
hlp = WideCharToMultiByte(locale->locinfo->lc_codepage,
WC_NO_BEST_FIT_CHARS, wcstr, 1, p, len, &default_char, NULL);
if(!hlp || *p=='\0')
break;
p += hlp;
len -= hlp;
wcstr++;
*ret += 1;
}
if(!len && size<=count) {
MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
*mbstr = '\0';
*MSVCRT__errno() = MSVCRT_ERANGE;
return MSVCRT_ERANGE;
}
if(*wcstr == '\0')
*ret += 1;
*p = '\0';
return 0;
}
/*********************************************************************
* wcstombs_s (MSVCRT.@)
*/
int CDECL MSVCRT_wcstombs_s(MSVCRT_size_t *ret, char *mbstr,
MSVCRT_size_t size, const MSVCRT_wchar_t *wcstr, MSVCRT_size_t count)
{
return MSVCRT__wcstombs_s_l(ret, mbstr, size, wcstr, count, NULL);
}
/*********************************************************************
* wcstod (MSVCRT.@)
*/