From 3af24fe1f41d628ed64d958fc537645bd1313875 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Tue, 23 Dec 2014 17:44:28 +0100 Subject: [PATCH] msvcrt: Add _wcsset_s implementation. --- dlls/msvcr100/msvcr100.spec | 2 +- dlls/msvcr110/msvcr110.spec | 2 +- dlls/msvcr120/msvcr120.spec | 2 +- dlls/msvcr120_app/msvcr120_app.spec | 2 +- dlls/msvcr80/msvcr80.spec | 2 +- dlls/msvcr90/msvcr90.spec | 2 +- dlls/msvcrt/msvcrt.spec | 2 +- dlls/msvcrt/tests/string.c | 37 +++++++++++++++++++++++++++++ dlls/msvcrt/wcs.c | 20 ++++++++++++++++ 9 files changed, 64 insertions(+), 7 deletions(-) diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec index a6e7771a731..29cbe7fb5fc 100644 --- a/dlls/msvcr100/msvcr100.spec +++ b/dlls/msvcr100/msvcr100.spec @@ -1509,7 +1509,7 @@ @ stub _wcsnset_s @ cdecl _wcsrev(wstr) MSVCRT__wcsrev @ cdecl _wcsset(wstr long) MSVCRT__wcsset -@ stub _wcsset_s +@ cdecl _wcsset_s(wstr long long) MSVCRT__wcsset_s @ cdecl _wcstod_l(wstr ptr) MSVCRT__wcstod_l @ cdecl -ret64 _wcstoi64(wstr ptr long) MSVCRT__wcstoi64 @ cdecl -ret64 _wcstoi64_l(wstr ptr long ptr) MSVCRT__wcstoi64_l diff --git a/dlls/msvcr110/msvcr110.spec b/dlls/msvcr110/msvcr110.spec index 141697cb045..9017921b163 100644 --- a/dlls/msvcr110/msvcr110.spec +++ b/dlls/msvcr110/msvcr110.spec @@ -1868,7 +1868,7 @@ @ stub _wcsnset_s @ cdecl _wcsrev(wstr) MSVCRT__wcsrev @ cdecl _wcsset(wstr long) MSVCRT__wcsset -@ stub _wcsset_s +@ cdecl _wcsset_s(wstr long long) MSVCRT__wcsset_s @ cdecl _wcstod_l(wstr ptr) MSVCRT__wcstod_l @ cdecl -ret64 _wcstoi64(wstr ptr long) MSVCRT__wcstoi64 @ cdecl -ret64 _wcstoi64_l(wstr ptr long ptr) MSVCRT__wcstoi64_l diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec index 9c765b3d2a3..355fe1762a6 100644 --- a/dlls/msvcr120/msvcr120.spec +++ b/dlls/msvcr120/msvcr120.spec @@ -1883,7 +1883,7 @@ @ stub _wcsnset_s @ cdecl _wcsrev(wstr) MSVCRT__wcsrev @ cdecl _wcsset(wstr long) MSVCRT__wcsset -@ stub _wcsset_s +@ cdecl _wcsset_s(wstr long long) MSVCRT__wcsset_s @ cdecl _wcstod_l(wstr ptr) MSVCRT__wcstod_l @ stub _wcstof_l @ cdecl -ret64 _wcstoi64(wstr ptr long) MSVCRT__wcstoi64 diff --git a/dlls/msvcr120_app/msvcr120_app.spec b/dlls/msvcr120_app/msvcr120_app.spec index 5d73441c30c..dd440c94122 100644 --- a/dlls/msvcr120_app/msvcr120_app.spec +++ b/dlls/msvcr120_app/msvcr120_app.spec @@ -1579,7 +1579,7 @@ @ stub _wcsnset_s @ cdecl _wcsrev(wstr) msvcr120._wcsrev @ cdecl _wcsset(wstr long) msvcr120._wcsset -@ stub _wcsset_s +@ cdecl _wcsset_s(wstr long long) msvcr120._wcsset_s @ cdecl _wcstod_l(wstr ptr) msvcr120._wcstod_l @ stub _wcstof_l @ cdecl -ret64 _wcstoi64(wstr ptr long) msvcr120._wcstoi64 diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec index fcad7cd9393..fbe42f3b231 100644 --- a/dlls/msvcr80/msvcr80.spec +++ b/dlls/msvcr80/msvcr80.spec @@ -1189,7 +1189,7 @@ @ stub _wcsnset_s @ cdecl _wcsrev(wstr) MSVCRT__wcsrev @ cdecl _wcsset(wstr long) MSVCRT__wcsset -@ stub _wcsset_s +@ cdecl _wcsset_s(wstr long long) MSVCRT__wcsset_s @ cdecl _wcstod_l(wstr ptr) MSVCRT__wcstod_l @ cdecl -ret64 _wcstoi64(wstr ptr long) MSVCRT__wcstoi64 @ cdecl -ret64 _wcstoi64_l(wstr ptr long ptr) MSVCRT__wcstoi64_l diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec index 7328b463749..9623aa5b4cb 100644 --- a/dlls/msvcr90/msvcr90.spec +++ b/dlls/msvcr90/msvcr90.spec @@ -1164,7 +1164,7 @@ @ stub _wcsnset_s @ cdecl _wcsrev(wstr) MSVCRT__wcsrev @ cdecl _wcsset(wstr long) MSVCRT__wcsset -@ stub _wcsset_s +@ cdecl _wcsset_s(wstr long long) MSVCRT__wcsset_s @ cdecl _wcstod_l(wstr ptr) MSVCRT__wcstod_l @ cdecl -ret64 _wcstoi64(wstr ptr long) MSVCRT__wcstoi64 @ cdecl -ret64 _wcstoi64_l(wstr ptr long ptr) MSVCRT__wcstoi64_l diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec index 37046c3d4f5..141cd9e1b3c 100644 --- a/dlls/msvcrt/msvcrt.spec +++ b/dlls/msvcrt/msvcrt.spec @@ -1120,7 +1120,7 @@ # stub _wcsnset_s(wstr long long) @ cdecl _wcsrev(wstr) MSVCRT__wcsrev @ cdecl _wcsset(wstr long) MSVCRT__wcsset -# stub _wcsset_s(wstr long) +@ cdecl _wcsset_s(wstr long long) MSVCRT__wcsset_s @ cdecl _wcstod_l(wstr ptr) MSVCRT__wcstod_l @ cdecl -ret64 _wcstoi64(wstr ptr long) MSVCRT__wcstoi64 @ cdecl -ret64 _wcstoi64_l(wstr ptr long ptr) MSVCRT__wcstoi64_l diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 17880351b51..e2d53d43720 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -90,6 +90,7 @@ static size_t (__cdecl *p_mbrlen)(const char*, size_t, mbstate_t*); static size_t (__cdecl *p_mbrtowc)(wchar_t*, const char*, size_t, mbstate_t*); static int (__cdecl *p__atodbl_l)(_CRT_DOUBLE*,char*,_locale_t); static int (__cdecl *p__strnset_s)(char*,size_t,int,size_t); +static int (__cdecl *p__wcsset_s)(wchar_t*,size_t,wchar_t); #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y) #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y) @@ -2749,6 +2750,40 @@ static void test__strnset_s(void) ok(!buf[0] && buf[1]=='c' && buf[2]=='b', "buf = %s\n", buf); } +static void test__wcsset_s(void) +{ + wchar_t str[10]; + int r; + + if(!p__wcsset_s) { + win_skip("_wcsset_s not available\n"); + return; + } + + r = p__wcsset_s(NULL, 0, 'a'); + ok(r == EINVAL, "r = %d\n", r); + + str[0] = 'a'; + r = p__wcsset_s(str, 0, 'a'); + ok(r == EINVAL, "r = %d\n", r); + ok(str[0] == 'a', "str[0] = %d\n", str[0]); + + str[0] = 'a'; + str[1] = 'b'; + r = p__wcsset_s(str, 2, 'c'); + ok(r == EINVAL, "r = %d\n", r); + ok(!str[0], "str[0] = %d\n", str[0]); + ok(str[1] == 'b', "str[1] = %d\n", str[1]); + + str[0] = 'a'; + str[1] = 0; + str[2] = 'b'; + r = p__wcsset_s(str, 3, 'c'); + ok(str[0] == 'c', "str[0] = %d\n", str[0]); + ok(str[1] == 0, "str[1] = %d\n", str[1]); + ok(str[2] == 'b', "str[2] = %d\n", str[2]); +} + START_TEST(string) { char mem[100]; @@ -2797,6 +2832,7 @@ START_TEST(string) p_mbsrtowcs = (void*)GetProcAddress(hMsvcrt, "mbsrtowcs"); p__atodbl_l = (void*)GetProcAddress(hMsvcrt, "_atodbl_l"); p__strnset_s = (void*)GetProcAddress(hMsvcrt, "_strnset_s"); + p__wcsset_s = (void*)GetProcAddress(hMsvcrt, "_wcsset_s"); /* MSVCRT memcpy behaves like memmove for overlapping moves, MFC42 CString::Insert seems to rely on that behaviour */ @@ -2851,4 +2887,5 @@ START_TEST(string) test_strncpy(); test_strxfrm(); test__strnset_s(); + test__wcsset_s(); } diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index a6a4fe71aff..935c2649e60 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -184,6 +184,26 @@ MSVCRT_wchar_t* CDECL MSVCRT__wcsrev( MSVCRT_wchar_t* str ) return ret; } +/********************************************************************* + * _wcsset_s (MSVCRT.@) + */ +int CDECL MSVCRT__wcsset_s( MSVCRT_wchar_t *str, MSVCRT_size_t n, MSVCRT_wchar_t c ) +{ + MSVCRT_wchar_t *p = str; + + if(!MSVCRT_CHECK_PMT(str != NULL)) return MSVCRT_EINVAL; + if(!MSVCRT_CHECK_PMT(n)) return MSVCRT_EINVAL; + + while(*p && --n) *p++ = c; + if(!n) { + str[0] = 0; + MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0); + *MSVCRT__errno() = MSVCRT_EINVAL; + return MSVCRT_EINVAL; + } + return 0; +} + /********************************************************************* * _wcsset (MSVCRT.@) */