msvcp120: Add a helper for tr2_sys__Equivalent.

Signed-off-by: Sven Baars <sven.wine@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Sven Baars 2019-10-21 20:01:45 +02:00 committed by Alexandre Julliard
parent e90cca8e7a
commit fb1fa3a404
2 changed files with 29 additions and 41 deletions

View File

@ -1230,6 +1230,7 @@ static void test_tr2_sys__Equivalent(void)
char temp_path[MAX_PATH], current_path[MAX_PATH]; 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 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 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 { struct {
char const *path1; char const *path1;
char const *path2; 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); ok(val == 1, "tr2_sys__Equivalent(): expect: 1, got %d\n", val);
val = p_tr2_sys__Equivalent_wchar(testW, testW2); val = p_tr2_sys__Equivalent_wchar(testW, testW2);
ok(val == 0, "tr2_sys__Equivalent(): expect: 0, got %d\n", val); 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/f1"), "expect tr2_test_dir/f1 to exist\n");
ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n"); ok(DeleteFileA("tr2_test_dir/f2"), "expect tr2_test_dir/f2 to exist\n");

View File

@ -14680,34 +14680,17 @@ ULONGLONG __cdecl tr2_sys__File_size(char const* path)
return ((ULONGLONG)(fad.nFileSizeHigh) << 32) + fad.nFileSizeLow; return ((ULONGLONG)(fad.nFileSizeHigh) << 32) + fad.nFileSizeLow;
} }
/* ?_Equivalent@sys@tr2@std@@YAHPBD0@Z */ static int equivalent_handles(HANDLE h1, HANDLE h2)
/* ?_Equivalent@sys@tr2@std@@YAHPEBD0@Z */
int __cdecl tr2_sys__Equivalent(char const* path1, char const* path2)
{ {
HANDLE h1, h2;
int ret; int ret;
BY_HANDLE_FILE_INFORMATION info1, info2; 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, if(h1 == INVALID_HANDLE_VALUE)
NULL, OPEN_EXISTING, 0, 0); return h2 == INVALID_HANDLE_VALUE ? -1 : 0;
h2 = CreateFileA(path2, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, else if(h2 == INVALID_HANDLE_VALUE)
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; return 0;
}
ret = GetFileInformationByHandle(h1, &info1) && GetFileInformationByHandle(h2, &info2); ret = GetFileInformationByHandle(h1, &info1) && GetFileInformationByHandle(h2, &info2);
CloseHandle(h1);
CloseHandle(h2);
if(!ret) if(!ret)
return -1; return -1;
return (info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber return (info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber
@ -14716,6 +14699,25 @@ int __cdecl tr2_sys__Equivalent(char const* path1, char const* path2)
); );
} }
/* ?_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;
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);
ret = equivalent_handles(h1, h2);
CloseHandle(h1);
CloseHandle(h2);
return ret;
}
/* ?_Current_get@sys@tr2@std@@YAPADAAY0BAE@D@Z */ /* ?_Current_get@sys@tr2@std@@YAPADAAY0BAE@D@Z */
/* ?_Current_get@sys@tr2@std@@YAPEADAEAY0BAE@D@Z */ /* ?_Current_get@sys@tr2@std@@YAPEADAEAY0BAE@D@Z */
char* __cdecl tr2_sys__Current_get(char *current_path) char* __cdecl tr2_sys__Current_get(char *current_path)
@ -15617,34 +15619,17 @@ int __cdecl tr2_sys__Equivalent_wchar(WCHAR const* path1, WCHAR const* path2)
{ {
HANDLE h1, h2; HANDLE h1, h2;
int ret; int ret;
BY_HANDLE_FILE_INFORMATION info1, info2;
TRACE("(%s %s)\n", debugstr_w(path1), debugstr_w(path2)); TRACE("(%s %s)\n", debugstr_w(path1), debugstr_w(path2));
h1 = CreateFileW(path1, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, h1 = CreateFileW(path1, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0); NULL, OPEN_EXISTING, 0, 0);
h2 = CreateFileW(path2, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, h2 = CreateFileW(path2, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0); NULL, OPEN_EXISTING, 0, 0);
if(h1 == INVALID_HANDLE_VALUE) { ret = equivalent_handles(h1, h2);
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);
CloseHandle(h1); CloseHandle(h1);
CloseHandle(h2); CloseHandle(h2);
if(!ret) return ret;
return -1;
return (info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber
&& info1.nFileIndexHigh == info2.nFileIndexHigh
&& info1.nFileIndexLow == info2.nFileIndexLow
);
} }
/* ?_Current_get@sys@tr2@std@@YAPA_WAAY0BAE@_W@Z */ /* ?_Current_get@sys@tr2@std@@YAPA_WAAY0BAE@_W@Z */