Commit 3ebd2f0b authored by Zhiyi Zhang's avatar Zhiyi Zhang Committed by Alexandre Julliard

kernel32: Implement FindStringOrdinal.

parent 0d4a1f7b
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
@ stub EnumResourceTypesExA @ stub EnumResourceTypesExA
@ stub EnumResourceTypesExW @ stub EnumResourceTypesExW
@ stdcall FindResourceExW(long wstr wstr long) kernel32.FindResourceExW @ stdcall FindResourceExW(long wstr wstr long) kernel32.FindResourceExW
@ stub FindStringOrdinal @ stdcall FindStringOrdinal(long wstr long wstr long long) kernel32.FindStringOrdinal
@ stdcall FreeLibrary(long) kernel32.FreeLibrary @ stdcall FreeLibrary(long) kernel32.FreeLibrary
@ stdcall FreeLibraryAndExitThread(long long) kernel32.FreeLibraryAndExitThread @ stdcall FreeLibraryAndExitThread(long long) kernel32.FreeLibraryAndExitThread
@ stdcall FreeResource(long) kernel32.FreeResource @ stdcall FreeResource(long) kernel32.FreeResource
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
@ stub EnumResourceTypesExA @ stub EnumResourceTypesExA
@ stub EnumResourceTypesExW @ stub EnumResourceTypesExW
@ stdcall FindResourceExW(long wstr wstr long) kernel32.FindResourceExW @ stdcall FindResourceExW(long wstr wstr long) kernel32.FindResourceExW
@ stub FindStringOrdinal @ stdcall FindStringOrdinal(long wstr long wstr long long) kernel32.FindStringOrdinal
@ stdcall FreeLibrary(long) kernel32.FreeLibrary @ stdcall FreeLibrary(long) kernel32.FreeLibrary
@ stdcall FreeLibraryAndExitThread(long long) kernel32.FreeLibraryAndExitThread @ stdcall FreeLibraryAndExitThread(long long) kernel32.FreeLibraryAndExitThread
@ stdcall FreeResource(long) kernel32.FreeResource @ stdcall FreeResource(long) kernel32.FreeResource
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
@ stub EnumResourceTypesExA @ stub EnumResourceTypesExA
@ stub EnumResourceTypesExW @ stub EnumResourceTypesExW
@ stdcall FindResourceExW(long wstr wstr long) kernel32.FindResourceExW @ stdcall FindResourceExW(long wstr wstr long) kernel32.FindResourceExW
@ stub FindStringOrdinal @ stdcall FindStringOrdinal(long wstr long wstr long long) kernel32.FindStringOrdinal
@ stdcall FreeLibrary(long) kernel32.FreeLibrary @ stdcall FreeLibrary(long) kernel32.FreeLibrary
@ stdcall FreeLibraryAndExitThread(long long) kernel32.FreeLibraryAndExitThread @ stdcall FreeLibraryAndExitThread(long long) kernel32.FreeLibraryAndExitThread
@ stdcall FreeResource(long) kernel32.FreeResource @ stdcall FreeResource(long) kernel32.FreeResource
......
...@@ -511,7 +511,7 @@ ...@@ -511,7 +511,7 @@
@ stdcall FindResourceExA(long str str long) @ stdcall FindResourceExA(long str str long)
@ stdcall FindResourceExW(long wstr wstr long) @ stdcall FindResourceExW(long wstr wstr long)
@ stdcall FindResourceW(long wstr wstr) @ stdcall FindResourceW(long wstr wstr)
# @ stub FindStringOrdinal @ stdcall FindStringOrdinal(long wstr long wstr long long)
@ stdcall FindVolumeClose(ptr) @ stdcall FindVolumeClose(ptr)
@ stdcall FindVolumeMountPointClose(ptr) @ stdcall FindVolumeMountPointClose(ptr)
@ stdcall FlsAlloc(ptr) @ stdcall FlsAlloc(ptr)
......
...@@ -5999,3 +5999,52 @@ INT WINAPI FindNLSStringEx(const WCHAR *localename, DWORD flags, const WCHAR *sr ...@@ -5999,3 +5999,52 @@ INT WINAPI FindNLSStringEx(const WCHAR *localename, DWORD flags, const WCHAR *sr
return -1; return -1;
} }
/******************************************************************************
* FindStringOrdinal (KERNEL32.@)
*/
INT WINAPI FindStringOrdinal(DWORD flag, const WCHAR *src, INT src_size, const WCHAR *val, INT val_size,
BOOL ignore_case)
{
INT offset, inc, count;
TRACE("%#x %s %d %s %d %d\n", flag, wine_dbgstr_w(src), src_size, wine_dbgstr_w(val), val_size, ignore_case);
if (!src || !val)
{
SetLastError(ERROR_INVALID_PARAMETER);
return -1;
}
if (flag != FIND_FROMSTART && flag != FIND_FROMEND && flag != FIND_STARTSWITH && flag != FIND_ENDSWITH)
{
SetLastError(ERROR_INVALID_FLAGS);
return -1;
}
if (src_size == -1) src_size = strlenW(src);
if (val_size == -1) val_size = strlenW(val);
src_size -= val_size;
if (src_size < 0)
{
SetLastError(NO_ERROR);
return -1;
}
count = flag & (FIND_FROMSTART | FIND_FROMEND) ? src_size + 1 : 1;
offset = flag & (FIND_FROMSTART | FIND_STARTSWITH) ? 0 : src_size;
inc = flag & (FIND_FROMSTART | FIND_STARTSWITH) ? 1 : -1;
while (count--)
{
if (CompareStringOrdinal(src + offset, val_size, val, val_size, ignore_case) == CSTR_EQUAL)
{
SetLastError(NO_ERROR);
return offset;
}
offset += inc;
}
SetLastError(NO_ERROR);
return -1;
}
...@@ -107,6 +107,7 @@ static INT (WINAPI *pFindNLSStringEx)(LPCWSTR, DWORD, LPCWSTR, INT, LPCWSTR, INT ...@@ -107,6 +107,7 @@ static INT (WINAPI *pFindNLSStringEx)(LPCWSTR, DWORD, LPCWSTR, INT, LPCWSTR, INT
static LANGID (WINAPI *pSetThreadUILanguage)(LANGID); static LANGID (WINAPI *pSetThreadUILanguage)(LANGID);
static LANGID (WINAPI *pGetThreadUILanguage)(VOID); static LANGID (WINAPI *pGetThreadUILanguage)(VOID);
static INT (WINAPI *pNormalizeString)(NORM_FORM, LPCWSTR, INT, LPWSTR, INT); static INT (WINAPI *pNormalizeString)(NORM_FORM, LPCWSTR, INT, LPWSTR, INT);
static INT (WINAPI *pFindStringOrdinal)(DWORD, LPCWSTR lpStringSource, INT, LPCWSTR, INT, BOOL);
static void InitFunctionPointers(void) static void InitFunctionPointers(void)
{ {
...@@ -143,6 +144,7 @@ static void InitFunctionPointers(void) ...@@ -143,6 +144,7 @@ static void InitFunctionPointers(void)
X(SetThreadUILanguage); X(SetThreadUILanguage);
X(GetThreadUILanguage); X(GetThreadUILanguage);
X(NormalizeString); X(NormalizeString);
X(FindStringOrdinal);
mod = GetModuleHandleA("ntdll"); mod = GetModuleHandleA("ntdll");
X(RtlUpcaseUnicodeChar); X(RtlUpcaseUnicodeChar);
...@@ -5496,6 +5498,73 @@ static void test_FindNLSStringEx(void) ...@@ -5496,6 +5498,73 @@ static void test_FindNLSStringEx(void)
} }
} }
static void test_FindStringOrdinal(void)
{
static const WCHAR abc123aBcW[] = {'a', 'b', 'c', '1', '2', '3', 'a', 'B', 'c', 0};
static const WCHAR abcW[] = {'a', 'b', 'c', 0};
static const WCHAR aBcW[] = {'a', 'B', 'c', 0};
static const WCHAR aaaW[] = {'a', 'a', 'a', 0};
static const struct
{
DWORD flag;
const WCHAR *src;
INT src_size;
const WCHAR *val;
INT val_size;
BOOL ignore_case;
INT ret;
DWORD err;
}
tests[] =
{
/* Invalid */
{1, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, abcW, ARRAY_SIZE(abcW) - 1, FALSE, -1, ERROR_INVALID_FLAGS},
{FIND_FROMSTART, NULL, ARRAY_SIZE(abc123aBcW) - 1, abcW, ARRAY_SIZE(abcW) - 1, FALSE, -1,
ERROR_INVALID_PARAMETER},
{FIND_FROMSTART, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, NULL, ARRAY_SIZE(abcW) - 1, FALSE, -1,
ERROR_INVALID_PARAMETER},
{FIND_FROMSTART, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, NULL, 0, FALSE, -1, ERROR_INVALID_PARAMETER},
{FIND_FROMSTART, NULL, 0, abcW, ARRAY_SIZE(abcW) - 1, FALSE, -1, ERROR_INVALID_PARAMETER},
{FIND_FROMSTART, NULL, 0, NULL, 0, FALSE, -1, ERROR_INVALID_PARAMETER},
/* Case-insensitive */
{FIND_FROMSTART, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, abcW, ARRAY_SIZE(abcW) - 1, FALSE, 0, NO_ERROR},
{FIND_FROMEND, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, abcW, ARRAY_SIZE(abcW) - 1, FALSE, 0, NO_ERROR},
{FIND_STARTSWITH, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, abcW, ARRAY_SIZE(abcW) - 1, FALSE, 0, NO_ERROR},
{FIND_ENDSWITH, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, abcW, ARRAY_SIZE(abcW) - 1, FALSE, -1, NO_ERROR},
/* Case-sensitive */
{FIND_FROMSTART, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, aBcW, ARRAY_SIZE(aBcW) - 1, TRUE, 0, NO_ERROR},
{FIND_FROMEND, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, aBcW, ARRAY_SIZE(aBcW) - 1, TRUE, 6, NO_ERROR},
{FIND_STARTSWITH, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, aBcW, ARRAY_SIZE(aBcW) - 1, TRUE, 0, NO_ERROR},
{FIND_ENDSWITH, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, aBcW, ARRAY_SIZE(aBcW) - 1, TRUE, 6, NO_ERROR},
/* Other */
{FIND_FROMSTART, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, aaaW, ARRAY_SIZE(aaaW) - 1, FALSE, -1, NO_ERROR},
{FIND_FROMSTART, abc123aBcW, -1, abcW, ARRAY_SIZE(abcW) - 1, FALSE, 0, NO_ERROR},
{FIND_FROMSTART, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, abcW, -1, FALSE, 0, NO_ERROR},
{FIND_FROMSTART, abc123aBcW, 0, abcW, ARRAY_SIZE(abcW) - 1, FALSE, -1, NO_ERROR},
{FIND_FROMSTART, abc123aBcW, ARRAY_SIZE(abc123aBcW) - 1, abcW, 0, FALSE, 0, NO_ERROR},
{FIND_FROMSTART, abc123aBcW, 0, abcW, 0, FALSE, 0, NO_ERROR},
};
INT ret;
DWORD err;
INT i;
if (!pFindStringOrdinal)
{
win_skip("FindStringOrdinal is not available.\n");
return;
}
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
SetLastError(0xdeadbeef);
ret = pFindStringOrdinal(tests[i].flag, tests[i].src, tests[i].src_size, tests[i].val, tests[i].val_size,
tests[i].ignore_case);
err = GetLastError();
ok(ret == tests[i].ret, "Item %d expected %d, got %d\n", i, tests[i].ret, ret);
ok(err == tests[i].err, "Item %d expected %#x, got %#x\n", i, tests[i].err, err);
}
}
static void test_SetThreadUILanguage(void) static void test_SetThreadUILanguage(void)
{ {
LANGID res; LANGID res;
...@@ -5746,6 +5815,7 @@ START_TEST(locale) ...@@ -5746,6 +5815,7 @@ START_TEST(locale)
test_GetThreadPreferredUILanguages(); test_GetThreadPreferredUILanguages();
test_GetUserPreferredUILanguages(); test_GetUserPreferredUILanguages();
test_FindNLSStringEx(); test_FindNLSStringEx();
test_FindStringOrdinal();
test_SetThreadUILanguage(); test_SetThreadUILanguage();
test_NormalizeString(); test_NormalizeString();
/* this requires collation table patch to make it MS compatible */ /* this requires collation table patch to make it MS compatible */
......
...@@ -373,7 +373,7 @@ ...@@ -373,7 +373,7 @@
# @ stub FindPackagesByPackageFamily # @ stub FindPackagesByPackageFamily
@ stdcall FindResourceExW(long wstr wstr long) kernel32.FindResourceExW @ stdcall FindResourceExW(long wstr wstr long) kernel32.FindResourceExW
@ stdcall FindResourceW(long wstr wstr) kernel32.FindResourceW @ stdcall FindResourceW(long wstr wstr) kernel32.FindResourceW
@ stub FindStringOrdinal @ stdcall FindStringOrdinal(long wstr long wstr long long) kernel32.FindStringOrdinal
@ stdcall FindVolumeClose(ptr) kernel32.FindVolumeClose @ stdcall FindVolumeClose(ptr) kernel32.FindVolumeClose
@ stdcall FlsAlloc(ptr) kernel32.FlsAlloc @ stdcall FlsAlloc(ptr) kernel32.FlsAlloc
@ stdcall FlsFree(long) kernel32.FlsFree @ stdcall FlsFree(long) kernel32.FlsFree
......
...@@ -28,6 +28,7 @@ typedef void *DLL_DIRECTORY_COOKIE, **PDLL_DIRECTORY_COOKIE; ...@@ -28,6 +28,7 @@ typedef void *DLL_DIRECTORY_COOKIE, **PDLL_DIRECTORY_COOKIE;
WINBASEAPI DLL_DIRECTORY_COOKIE WINAPI AddDllDirectory(const WCHAR *); WINBASEAPI DLL_DIRECTORY_COOKIE WINAPI AddDllDirectory(const WCHAR *);
WINBASEAPI BOOL WINAPI RemoveDllDirectory(DLL_DIRECTORY_COOKIE); WINBASEAPI BOOL WINAPI RemoveDllDirectory(DLL_DIRECTORY_COOKIE);
WINBASEAPI BOOL WINAPI SetDefaultDllDirectories(DWORD); WINBASEAPI BOOL WINAPI SetDefaultDllDirectories(DWORD);
WINBASEAPI INT WINAPI FindStringOrdinal(DWORD, const WCHAR *, INT, const WCHAR *, INT, BOOL);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
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