Module: wine Branch: master Commit: fb1fa3a404b88d120abef9c3c4b40bdced25ce76 URL: https://source.winehq.org/git/wine.git/?a=commit;h=fb1fa3a404b88d120abef9c3c...
Author: Sven Baars sven.wine@gmail.com Date: Mon Oct 21 20:01:45 2019 +0200
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
---
dlls/msvcp120/tests/msvcp120.c | 3 ++ dlls/msvcp90/ios.c | 65 ++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 40 deletions(-)
diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c index 8f7b75aab4..d484cdd7ed 100644 --- a/dlls/msvcp120/tests/msvcp120.c +++ b/dlls/msvcp120/tests/msvcp120.c @@ -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"); diff --git a/dlls/msvcp90/ios.c b/dlls/msvcp90/ios.c index 84174e4f95..8f0e5cfd7b 100644 --- a/dlls/msvcp90/ios.c +++ b/dlls/msvcp90/ios.c @@ -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 */