Commit 9b52a967 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

ntdll: Fix _strnicmp implementation to not depend on locale.

parent 98517857
...@@ -258,21 +258,36 @@ INT __cdecl _memicmp( LPCSTR s1, LPCSTR s2, DWORD len ) ...@@ -258,21 +258,36 @@ INT __cdecl _memicmp( LPCSTR s1, LPCSTR s2, DWORD len )
/********************************************************************* /*********************************************************************
* _stricmp (NTDLL.@) * _strnicmp (NTDLL.@)
* _strcmpi (NTDLL.@)
*/ */
int __cdecl _stricmp( LPCSTR str1, LPCSTR str2 ) int __cdecl _strnicmp( LPCSTR str1, LPCSTR str2, size_t n )
{ {
return strcasecmp( str1, str2 ); int l1, l2;
while (n--)
{
l1 = (unsigned char)NTDLL_tolower(*str1);
l2 = (unsigned char)NTDLL_tolower(*str2);
if (l1 != l2)
{
if (sizeof(void *) > sizeof(int)) return l1 - l2;
return l1 - l2 > 0 ? 1 : -1;
}
if (!l1) return 0;
str1++;
str2++;
}
return 0;
} }
/********************************************************************* /*********************************************************************
* _strnicmp (NTDLL.@) * _stricmp (NTDLL.@)
* _strcmpi (NTDLL.@)
*/ */
int __cdecl _strnicmp( LPCSTR str1, LPCSTR str2, size_t n ) int __cdecl _stricmp( LPCSTR str1, LPCSTR str2 )
{ {
return strncasecmp( str1, str2, n ); return _strnicmp( str1, str2, -1 );
} }
......
...@@ -64,6 +64,7 @@ static int (WINAPIV *p__snprintf)(char *, size_t, const char *, ...); ...@@ -64,6 +64,7 @@ static int (WINAPIV *p__snprintf)(char *, size_t, const char *, ...);
static int (__cdecl *p_tolower)(int); static int (__cdecl *p_tolower)(int);
static int (__cdecl *p_toupper)(int); static int (__cdecl *p_toupper)(int);
static int (__cdecl *p__strnicmp)(LPCSTR,LPCSTR,size_t);
static void InitFunctionPtrs(void) static void InitFunctionPtrs(void)
{ {
...@@ -105,6 +106,7 @@ static void InitFunctionPtrs(void) ...@@ -105,6 +106,7 @@ static void InitFunctionPtrs(void)
p_tolower = (void *)GetProcAddress(hntdll, "tolower"); p_tolower = (void *)GetProcAddress(hntdll, "tolower");
p_toupper = (void *)GetProcAddress(hntdll, "toupper"); p_toupper = (void *)GetProcAddress(hntdll, "toupper");
p__strnicmp = (void *)GetProcAddress(hntdll, "_strnicmp");
} /* if */ } /* if */
} }
...@@ -1381,6 +1383,29 @@ static void test_toupper(void) ...@@ -1381,6 +1383,29 @@ static void test_toupper(void)
} }
} }
static void test__strnicmp(void)
{
BOOL is_win64 = (sizeof(void *) > sizeof(int));
int ret;
ok(p__strnicmp != NULL, "_strnicmp is not available\n");
ret = p__strnicmp("a", "C", 1);
ok(ret == (is_win64 ? -2 : -1), "_strnicmp returned %d\n", ret);
ret = p__strnicmp("a", "c", 1);
ok(ret == (is_win64 ? -2 : -1), "_strnicmp returned %d\n", ret);
ret = p__strnicmp("C", "a", 1);
ok(ret == (is_win64 ? 2 : 1), "_strnicmp returned %d\n", ret);
ret = p__strnicmp("c", "a", 1);
ok(ret == (is_win64 ? 2 : 1), "_strnicmp returned %d\n", ret);
ret = p__strnicmp("ijk0", "IJK1", 3);
ok(!ret, "_strnicmp returned %d\n", ret);
ret = p__strnicmp("ijk0", "IJK1", 4);
ok(ret == -1, "_strnicmp returned %d\n", ret);
ret = p__strnicmp("ijk\0X", "IJK\0Y", 5);
ok(!ret, "_strnicmp returned %d\n", ret);
}
START_TEST(string) START_TEST(string)
{ {
InitFunctionPtrs(); InitFunctionPtrs();
...@@ -1419,4 +1444,5 @@ START_TEST(string) ...@@ -1419,4 +1444,5 @@ START_TEST(string)
test__snprintf(); test__snprintf();
test_tolower(); test_tolower();
test_toupper(); test_toupper();
test__strnicmp();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment