From 841fbd5b141db7bed7445e95f7accd6cb393c3de Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Tue, 14 Jul 2020 20:22:45 +0200 Subject: [PATCH] msvcrt: Don't use strcmpW in wcscmp. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcrt/tests/string.c | 15 +++++++++++++++ dlls/msvcrt/wcs.c | 28 +++++++++++++++++++--------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 46eb0cc080e..b5b877e7ece 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -4210,6 +4210,20 @@ static void test_iswdigit(void) } } +static void test_wcscmp(void) +{ + int r; + + r = wcscmp(L"a", L"z"); + ok(r == -1, "wcscmp returned %d\n", r); + + r = wcscmp(L"z", L"a"); + ok(r == 1, "wcscmp returned %d\n", r); + + r = wcscmp(L"f", L"f"); + ok(!r, "wcscmp returned %d\n", r); +} + START_TEST(string) { char mem[100]; @@ -4359,4 +4373,5 @@ START_TEST(string) test_C_locale(); test_strstr(); test_iswdigit(); + test_wcscmp(); } diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index 73ade3be73d..70a8d6201fc 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -1583,6 +1583,24 @@ int WINAPIV MSVCRT_swprintf_p_l(MSVCRT_wchar_t *buffer, MSVCRT_size_t length, return r; } +/********************************************************************* + * wcscmp (MSVCRT.@) + */ +int CDECL MSVCRT_wcscmp(const MSVCRT_wchar_t *str1, const MSVCRT_wchar_t *str2) +{ + while (*str1 && (*str1 == *str2)) + { + str1++; + str2++; + } + + if (*str1 < *str2) + return -1; + if (*str1 > *str2) + return 1; + return 0; +} + /********************************************************************* * _wcscoll_l (MSVCRT.@) */ @@ -1596,7 +1614,7 @@ int CDECL MSVCRT__wcscoll_l(const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* st locinfo = locale->locinfo; if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) - return strcmpW(str1, str2); + return MSVCRT_wcscmp(str1, str2); return CompareStringW(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0, str1, -1, str2, -1)-CSTR_EQUAL; } @@ -2668,11 +2686,3 @@ MSVCRT_size_t CDECL MSVCRT_wcsxfrm(MSVCRT_wchar_t *dest, { return MSVCRT__wcsxfrm_l(dest, src, len, NULL); } - -/********************************************************************* - * wcscmp (MSVCRT.@) - */ -int CDECL MSVCRT_wcscmp(const MSVCRT_wchar_t *str1, const MSVCRT_wchar_t *str2) -{ - return strcmpW(str1, str2); -}