kernelbase: Implement PathCchRemoveBackslash.

Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zhiyi Zhang 2018-11-23 11:17:40 +08:00 committed by Alexandre Julliard
parent ceb5d59816
commit 1e36dbb297
5 changed files with 62 additions and 2 deletions

View File

@ -11,7 +11,7 @@
@ stub PathCchCombineEx @ stub PathCchCombineEx
@ stdcall PathCchFindExtension(wstr long ptr) kernelbase.PathCchFindExtension @ stdcall PathCchFindExtension(wstr long ptr) kernelbase.PathCchFindExtension
@ stdcall PathCchIsRoot(wstr) kernelbase.PathCchIsRoot @ stdcall PathCchIsRoot(wstr) kernelbase.PathCchIsRoot
@ stub PathCchRemoveBackslash @ stdcall PathCchRemoveBackslash(wstr long) kernelbase.PathCchRemoveBackslash
@ stdcall PathCchRemoveBackslashEx(wstr long ptr ptr) kernelbase.PathCchRemoveBackslashEx @ stdcall PathCchRemoveBackslashEx(wstr long ptr ptr) kernelbase.PathCchRemoveBackslashEx
@ stdcall PathCchRemoveExtension(wstr long) kernelbase.PathCchRemoveExtension @ stdcall PathCchRemoveExtension(wstr long) kernelbase.PathCchRemoveExtension
@ stub PathCchRemoveFileSpec @ stub PathCchRemoveFileSpec

View File

@ -1040,7 +1040,7 @@
# @ stub PathCchCombineEx # @ stub PathCchCombineEx
@ stdcall PathCchFindExtension(wstr long ptr) @ stdcall PathCchFindExtension(wstr long ptr)
@ stdcall PathCchIsRoot(wstr) @ stdcall PathCchIsRoot(wstr)
# @ stub PathCchRemoveBackslash @ stdcall PathCchRemoveBackslash(wstr long)
@ stdcall PathCchRemoveBackslashEx(wstr long ptr ptr) @ stdcall PathCchRemoveBackslashEx(wstr long ptr ptr)
@ stdcall PathCchRemoveExtension(wstr long) @ stdcall PathCchRemoveExtension(wstr long)
# @ stub PathCchRemoveFileSpec # @ stub PathCchRemoveFileSpec

View File

@ -278,6 +278,16 @@ BOOL WINAPI PathCchIsRoot(const WCHAR *path)
return FALSE; return FALSE;
} }
HRESULT WINAPI PathCchRemoveBackslash(WCHAR *path, SIZE_T path_size)
{
WCHAR *path_end;
SIZE_T free_size;
TRACE("%s %lu\n", debugstr_w(path), path_size);
return PathCchRemoveBackslashEx(path, path_size, &path_end, &free_size);
}
HRESULT WINAPI PathCchRemoveBackslashEx(WCHAR *path, SIZE_T path_size, WCHAR **path_end, SIZE_T *free_size) HRESULT WINAPI PathCchRemoveBackslashEx(WCHAR *path, SIZE_T path_size, WCHAR **path_end, SIZE_T *free_size)
{ {
const WCHAR *root_end; const WCHAR *root_end;

View File

@ -36,6 +36,7 @@ HRESULT (WINAPI *pPathCchAddExtension)(WCHAR *path, SIZE_T size, const WCHAR *ex
HRESULT (WINAPI *pPathCchCombineEx)(WCHAR *out, SIZE_T size, const WCHAR *path1, const WCHAR *path2, DWORD flags); HRESULT (WINAPI *pPathCchCombineEx)(WCHAR *out, SIZE_T size, const WCHAR *path1, const WCHAR *path2, DWORD flags);
HRESULT (WINAPI *pPathCchFindExtension)(const WCHAR *path, SIZE_T size, const WCHAR **extension); HRESULT (WINAPI *pPathCchFindExtension)(const WCHAR *path, SIZE_T size, const WCHAR **extension);
BOOL (WINAPI *pPathCchIsRoot)(const WCHAR *path); BOOL (WINAPI *pPathCchIsRoot)(const WCHAR *path);
HRESULT (WINAPI *pPathCchRemoveBackslash)(WCHAR *path, SIZE_T path_size);
HRESULT (WINAPI *pPathCchRemoveBackslashEx)(WCHAR *path, SIZE_T path_size, WCHAR **path_end, SIZE_T *free_size); HRESULT (WINAPI *pPathCchRemoveBackslashEx)(WCHAR *path, SIZE_T path_size, WCHAR **path_end, SIZE_T *free_size);
HRESULT (WINAPI *pPathCchRemoveExtension)(WCHAR *path, SIZE_T size); HRESULT (WINAPI *pPathCchRemoveExtension)(WCHAR *path, SIZE_T size);
HRESULT (WINAPI *pPathCchRenameExtension)(WCHAR *path, SIZE_T size, const WCHAR *extension); HRESULT (WINAPI *pPathCchRenameExtension)(WCHAR *path, SIZE_T size, const WCHAR *extension);
@ -593,6 +594,52 @@ static const struct removebackslashex_test removebackslashex_tests [] =
"\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}\\a", 50, 2, S_OK} "\\\\?\\Volume{e51a1864-6f2d-4019-b73d-f4e60e600c26}\\a", 50, 2, S_OK}
}; };
static void test_PathCchRemoveBackslash(void)
{
WCHAR pathW[PATHCCH_MAX_CCH];
CHAR pathA[PATHCCH_MAX_CCH];
HRESULT hr;
SIZE_T path_size;
INT i;
if (!pPathCchRemoveBackslash)
{
win_skip("PathCchRemoveBackslash() is not available.\n");
return;
}
/* No NULL check for path on Windows */
if (0)
{
hr = pPathCchRemoveBackslash(NULL, PATHCCH_MAX_CCH);
ok(hr == E_INVALIDARG, "expect hr %#x, got %#x\n", E_INVALIDARG, hr);
}
MultiByteToWideChar(CP_ACP, 0, "C:\\a\\", -1, pathW, ARRAY_SIZE(pathW));
hr = pPathCchRemoveBackslash(pathW, 0);
ok(hr == E_INVALIDARG, "expect hr %#x, got %#x\n", E_INVALIDARG, hr);
hr = pPathCchRemoveBackslash(pathW, PATHCCH_MAX_CCH + 1);
ok(hr == S_OK, "expect hr %#x, got %#x\n", S_OK, hr);
hr = pPathCchRemoveBackslash(pathW, PATHCCH_MAX_CCH);
ok(hr == S_FALSE, "expect hr %#x, got %#x\n", S_FALSE, hr);
for (i = 0; i < ARRAY_SIZE(removebackslashex_tests); i++)
{
const struct removebackslashex_test *t = removebackslashex_tests + i;
path_size = MultiByteToWideChar(CP_ACP, 0, t->path_in, -1, pathW, ARRAY_SIZE(pathW));
hr = pPathCchRemoveBackslash(pathW, path_size);
ok(hr == t->hr, "path %s expect result %#x, got %#x\n", t->path_in, t->hr, hr);
if (SUCCEEDED(hr))
{
WideCharToMultiByte(CP_ACP, 0, pathW, -1, pathA, ARRAY_SIZE(pathA), NULL, NULL);
ok(!lstrcmpA(pathA, t->path_out), "path %s expect output path %s, got %s\n", t->path_in, t->path_out,
pathA);
}
}
}
static void test_PathCchRemoveBackslashEx(void) static void test_PathCchRemoveBackslashEx(void)
{ {
WCHAR pathW[PATHCCH_MAX_CCH]; WCHAR pathW[PATHCCH_MAX_CCH];
@ -1221,6 +1268,7 @@ START_TEST(path)
pPathCchAddExtension = (void *)GetProcAddress(hmod, "PathCchAddExtension"); pPathCchAddExtension = (void *)GetProcAddress(hmod, "PathCchAddExtension");
pPathCchFindExtension = (void *)GetProcAddress(hmod, "PathCchFindExtension"); pPathCchFindExtension = (void *)GetProcAddress(hmod, "PathCchFindExtension");
pPathCchIsRoot = (void *)GetProcAddress(hmod, "PathCchIsRoot"); pPathCchIsRoot = (void *)GetProcAddress(hmod, "PathCchIsRoot");
pPathCchRemoveBackslash = (void *)GetProcAddress(hmod, "PathCchRemoveBackslash");
pPathCchRemoveBackslashEx = (void *)GetProcAddress(hmod, "PathCchRemoveBackslashEx"); pPathCchRemoveBackslashEx = (void *)GetProcAddress(hmod, "PathCchRemoveBackslashEx");
pPathCchRemoveExtension = (void *)GetProcAddress(hmod, "PathCchRemoveExtension"); pPathCchRemoveExtension = (void *)GetProcAddress(hmod, "PathCchRemoveExtension");
pPathCchRenameExtension = (void *)GetProcAddress(hmod, "PathCchRenameExtension"); pPathCchRenameExtension = (void *)GetProcAddress(hmod, "PathCchRenameExtension");
@ -1235,6 +1283,7 @@ START_TEST(path)
test_PathCchAddExtension(); test_PathCchAddExtension();
test_PathCchFindExtension(); test_PathCchFindExtension();
test_PathCchIsRoot(); test_PathCchIsRoot();
test_PathCchRemoveBackslash();
test_PathCchRemoveBackslashEx(); test_PathCchRemoveBackslashEx();
test_PathCchRemoveExtension(); test_PathCchRemoveExtension();
test_PathCchRenameExtension(); test_PathCchRenameExtension();

View File

@ -31,6 +31,7 @@ HRESULT WINAPI PathCchAddExtension(WCHAR *path, SIZE_T size, const WCHAR *extens
HRESULT WINAPI PathCchCombineEx(WCHAR *out, SIZE_T size, const WCHAR *path1, const WCHAR *path2, DWORD flags); HRESULT WINAPI PathCchCombineEx(WCHAR *out, SIZE_T size, const WCHAR *path1, const WCHAR *path2, DWORD flags);
HRESULT WINAPI PathCchFindExtension(const WCHAR *path, SIZE_T size, const WCHAR **extension); HRESULT WINAPI PathCchFindExtension(const WCHAR *path, SIZE_T size, const WCHAR **extension);
BOOL WINAPI PathCchIsRoot(const WCHAR *path); BOOL WINAPI PathCchIsRoot(const WCHAR *path);
HRESULT WINAPI PathCchRemoveBackslash(WCHAR *path, SIZE_T path_size);
HRESULT WINAPI PathCchRemoveBackslashEx(WCHAR *path, SIZE_T path_size, WCHAR **path_end, SIZE_T *free_size); HRESULT WINAPI PathCchRemoveBackslashEx(WCHAR *path, SIZE_T path_size, WCHAR **path_end, SIZE_T *free_size);
HRESULT WINAPI PathCchRemoveExtension(WCHAR *path, SIZE_T size); HRESULT WINAPI PathCchRemoveExtension(WCHAR *path, SIZE_T size);
HRESULT WINAPI PathCchRenameExtension(WCHAR *path, SIZE_T size, const WCHAR *extension); HRESULT WINAPI PathCchRenameExtension(WCHAR *path, SIZE_T size, const WCHAR *extension);