Commit fb1fa3a4 authored by Sven Baars's avatar Sven Baars Committed by Alexandre Julliard

msvcp120: Add a helper for tr2_sys__Equivalent.

parent e90cca8e
......@@ -1230,6 +1230,7 @@ static void test_tr2_sys__Equivalent(void)
char temp_path[MAX_PATH], current_path[MAX_PATH];
WCHAR testW[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','1',0};
WCHAR testW2[] = {'t','r','2','_','t','e','s','t','_','d','i','r','/','f','2',0};
WCHAR test_dirW[] = {'t','r','2','_','t','e','s','t','_','d','i','r',0};
struct {
char const *path1;
char const *path2;
......@@ -1273,6 +1274,8 @@ static void test_tr2_sys__Equivalent(void)
ok(val == 1, "tr2_sys__Equivalent(): expect: 1, got %d\n", val);
val = p_tr2_sys__Equivalent_wchar(testW, testW2);
ok(val == 0, "tr2_sys__Equivalent(): expect: 0, got %d\n", val);
val = p_tr2_sys__Equivalent_wchar(test_dirW, test_dirW);
ok(val == -1, "tr2_sys__Equivalent(): expect: -1, got %d\n", val);
ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n");
......
......@@ -14680,40 +14680,42 @@ ULONGLONG __cdecl tr2_sys__File_size(char const* path)
return ((ULONGLONG)(fad.nFileSizeHigh) << 32) + fad.nFileSizeLow;
}
static int equivalent_handles(HANDLE h1, HANDLE h2)
{
int ret;
BY_HANDLE_FILE_INFORMATION info1, info2;
if(h1 == INVALID_HANDLE_VALUE)
return h2 == INVALID_HANDLE_VALUE ? -1 : 0;
else if(h2 == INVALID_HANDLE_VALUE)
return 0;
ret = GetFileInformationByHandle(h1, &info1) && GetFileInformationByHandle(h2, &info2);
if(!ret)
return -1;
return (info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber
&& info1.nFileIndexHigh == info2.nFileIndexHigh
&& info1.nFileIndexLow == info2.nFileIndexLow
);
}
/* ?_Equivalent@sys@tr2@std@@YAHPBD0@Z */
/* ?_Equivalent@sys@tr2@std@@YAHPEBD0@Z */
int __cdecl tr2_sys__Equivalent(char const* path1, char const* path2)
{
HANDLE h1, h2;
int ret;
BY_HANDLE_FILE_INFORMATION info1, info2;
TRACE("(%s %s)\n", debugstr_a(path1), debugstr_a(path2));
h1 = CreateFileA(path1, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0);
h2 = CreateFileA(path2, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0);
if(h1 == INVALID_HANDLE_VALUE) {
if(h2 == INVALID_HANDLE_VALUE) {
return -1;
}else {
CloseHandle(h2);
return 0;
}
}else if(h2 == INVALID_HANDLE_VALUE) {
CloseHandle(h1);
return 0;
}
ret = GetFileInformationByHandle(h1, &info1) && GetFileInformationByHandle(h2, &info2);
ret = equivalent_handles(h1, h2);
CloseHandle(h1);
CloseHandle(h2);
if(!ret)
return -1;
return (info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber
&& info1.nFileIndexHigh == info2.nFileIndexHigh
&& info1.nFileIndexLow == info2.nFileIndexLow
);
return ret;
}
/* ?_Current_get@sys@tr2@std@@YAPADAAY0BAE@D@Z */
......@@ -15617,34 +15619,17 @@ int __cdecl tr2_sys__Equivalent_wchar(WCHAR const* path1, WCHAR const* path2)
{
HANDLE h1, h2;
int ret;
BY_HANDLE_FILE_INFORMATION info1, info2;
TRACE("(%s %s)\n", debugstr_w(path1), debugstr_w(path2));
h1 = CreateFileW(path1, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0);
h2 = CreateFileW(path2, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0);
if(h1 == INVALID_HANDLE_VALUE) {
if(h2 == INVALID_HANDLE_VALUE) {
return -1;
}else {
CloseHandle(h2);
return 0;
}
}else if(h2 == INVALID_HANDLE_VALUE) {
CloseHandle(h1);
return 0;
}
ret = GetFileInformationByHandle(h1, &info1) && GetFileInformationByHandle(h2, &info2);
ret = equivalent_handles(h1, h2);
CloseHandle(h1);
CloseHandle(h2);
if(!ret)
return -1;
return (info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber
&& info1.nFileIndexHigh == info2.nFileIndexHigh
&& info1.nFileIndexLow == info2.nFileIndexLow
);
return ret;
}
/* ?_Current_get@sys@tr2@std@@YAPA_WAAY0BAE@_W@Z */
......
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