Signed-off-by: Paul Gofman pgofman@codeweavers.com --- v2: - don't call SetLastError() on success.
dlls/msvcp140/msvcp140.spec | 2 +- dlls/msvcp140/tests/msvcp140.c | 62 ++++++++++++++++++++++++++++++++++ dlls/msvcp90/ios.c | 11 ++++++ dlls/msvcp_win/msvcp_win.spec | 2 +- 4 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcp140/msvcp140.spec b/dlls/msvcp140/msvcp140.spec index 3de0318a4d5..e7bdcd0378e 100644 --- a/dlls/msvcp140/msvcp140.spec +++ b/dlls/msvcp140/msvcp140.spec @@ -3632,7 +3632,7 @@ @ cdecl _Cnd_timedwait(ptr ptr ptr) @ cdecl _Cnd_unregister_at_thread_exit(ptr) @ cdecl _Cnd_wait(ptr ptr) -@ stub _Copy_file +@ cdecl _Copy_file(wstr wstr) @ stub _Cosh @ cdecl _Current_get(ptr) @ cdecl _Current_set(wstr) tr2_sys__Current_set_wchar diff --git a/dlls/msvcp140/tests/msvcp140.c b/dlls/msvcp140/tests/msvcp140.c index 14ba4a767d0..423c4c652b9 100644 --- a/dlls/msvcp140/tests/msvcp140.c +++ b/dlls/msvcp140/tests/msvcp140.c @@ -227,6 +227,7 @@ static int (__cdecl *p__Xtime_diff_to_millis2)(const xtime*, const xtime*); static int (__cdecl *p_xtime_get)(xtime*, int);
static void (__cdecl *p_Close_dir)(void*); +static DWORD (__cdecl *p_Copy_file)(WCHAR const *, WCHAR const *); static MSVCP_bool (__cdecl *p_Current_get)(WCHAR *); static MSVCP_bool (__cdecl *p_Current_set)(WCHAR const *); static int (__cdecl *p_Equivalent)(WCHAR const*, WCHAR const*); @@ -338,6 +339,7 @@ static BOOL init(void) SET(p_xtime_get, "xtime_get");
SET(p_Close_dir, "_Close_dir"); + SET(p_Copy_file, "_Copy_file"); SET(p_Current_get, "_Current_get"); SET(p_Current_set, "_Current_set"); SET(p_Equivalent, "_Equivalent"); @@ -1575,6 +1577,65 @@ static void test_cnd(void) CloseHandle(cm.initialized); }
+static void test_Copy_file(void) +{ + WCHAR origin_path[MAX_PATH], temp_path[MAX_PATH]; + HANDLE file; + DWORD ret; + + GetCurrentDirectoryW(MAX_PATH, origin_path); + GetTempPathW(MAX_PATH, temp_path); + ok(SetCurrentDirectoryW(temp_path), "SetCurrentDirectoryW to temp_path failed\n"); + + CreateDirectoryW(L"wine_test_dir", NULL); + + file = CreateFileW(L"wine_test_dir/f1", 0, 0, NULL, CREATE_NEW, 0, NULL); + ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n"); + ok(CloseHandle(file), "CloseHandle\n"); + + file = CreateFileW(L"wine_test_dir/f2", 0, 0, NULL, CREATE_NEW, 0, NULL); + ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n"); + ok(CloseHandle(file), "CloseHandle\n"); + SetFileAttributesW(L"wine_test_dir/f2", FILE_ATTRIBUTE_READONLY); + + ok(CreateDirectoryW(L"wine_test_dir/d1", NULL) || GetLastError() == ERROR_ALREADY_EXISTS, + "CreateDirectoryW failed.\n"); + + SetLastError(0xdeadbeef); + ret = p_Copy_file(L"wine_test_dir/f1", L"wine_test_dir/d1"); + ok(ret == ERROR_ACCESS_DENIED, "Got unexpected ret %lu.\n", ret); + ok(GetLastError() == ret, "Got unexpected err %lu.\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = p_Copy_file(L"wine_test_dir/f1", L"wine_test_dir/f2"); + ok(ret == ERROR_ACCESS_DENIED, "Got unexpected ret %lu.\n", ret); + ok(GetLastError() == ret, "Got unexpected err %lu.\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = p_Copy_file(L"wine_test_dir/f1", L"wine_test_dir/f3"); + ok(ret == ERROR_SUCCESS, "Got unexpected ret %lu.\n", ret); + ok(GetLastError() == ret, "Got unexpected err %lu.\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = p_Copy_file(L"wine_test_dir/f1", L"wine_test_dir/f3"); + ok(ret == ERROR_SUCCESS, "Got unexpected ret %lu.\n", ret); + todo_wine ok(GetLastError() == ret, "Got unexpected err %lu.\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = p_Copy_file(L"wine_test_dir/missing", L"wine_test_dir/f3"); + ok(ret == ERROR_FILE_NOT_FOUND, "Got unexpected ret %lu.\n", ret); + ok(GetLastError() == ret, "Got unexpected err %lu.\n", GetLastError()); + + ok(RemoveDirectoryW(L"wine_test_dir/d1"), "expect wine_test_dir to exist\n"); + ok(DeleteFileW(L"wine_test_dir/f1"), "expect wine_test_dir/f1 to exist\n"); + SetFileAttributesW(L"wine_test_dir/f2", FILE_ATTRIBUTE_NORMAL); + ok(DeleteFileW(L"wine_test_dir/f2"), "expect wine_test_dir/f2 to exist\n"); + ok(DeleteFileW(L"wine_test_dir/f3"), "expect wine_test_dir/f3 to exist\n"); + ok(RemoveDirectoryW(L"wine_test_dir"), "expect wine_test_dir to exist\n"); + + ok(SetCurrentDirectoryW(origin_path), "SetCurrentDirectoryW to origin_path failed\n"); +} + START_TEST(msvcp140) { if(!init()) return; @@ -1601,5 +1662,6 @@ START_TEST(msvcp140) test__Syserror_map(); test_Equivalent(); test_cnd(); + test_Copy_file(); FreeLibrary(msvcp); } diff --git a/dlls/msvcp90/ios.c b/dlls/msvcp90/ios.c index 61308f49203..ef2c122f17f 100644 --- a/dlls/msvcp90/ios.c +++ b/dlls/msvcp90/ios.c @@ -15776,6 +15776,17 @@ enum file_type __cdecl _Stat(WCHAR const* path, int* permissions) return (attr & FILE_ATTRIBUTE_DIRECTORY) ? directory_file : regular_file; }
+/* _Copy_file, msvcp140 version */ +DWORD __cdecl _Copy_file(WCHAR const* src, WCHAR const* dst) +{ + TRACE("src %s, dst %s.\n", debugstr_w(src), debugstr_w(dst)); + + if (CopyFileW(src, dst, FALSE)) + return ERROR_SUCCESS; + + return GetLastError(); +} + /* ?_Lstat@sys@tr2@std@@YA?AW4file_type@123@PB_WAAH@Z */ /* ?_Lstat@sys@tr2@std@@YA?AW4file_type@123@PEB_WAEAH@Z */ enum file_type __cdecl tr2_sys__Lstat_wchar(WCHAR const* path, int* err_code) diff --git a/dlls/msvcp_win/msvcp_win.spec b/dlls/msvcp_win/msvcp_win.spec index a15fb5c7ee3..3ba0ce1dfba 100644 --- a/dlls/msvcp_win/msvcp_win.spec +++ b/dlls/msvcp_win/msvcp_win.spec @@ -3632,7 +3632,7 @@ @ cdecl _Cnd_timedwait(ptr ptr ptr) msvcp140._Cnd_timedwait @ cdecl _Cnd_unregister_at_thread_exit(ptr) msvcp140._Cnd_unregister_at_thread_exit @ cdecl _Cnd_wait(ptr ptr) msvcp140._Cnd_wait -@ stub _Copy_file +@ cdecl _Copy_file(wstr wstr) msvcp140._Copy_file @ stub _Cosh @ cdecl _Current_get(ptr) msvcp140._Current_get @ cdecl _Current_set(wstr) msvcp140._Current_set
Signed-off-by: Paul Gofman pgofman@codeweavers.com --- v2: - added patch.
dlls/kernel32/tests/file.c | 7 +++++++ dlls/kernelbase/file.c | 1 + dlls/msvcp140/tests/msvcp140.c | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 4f8fb92c96b..485ed9e7d30 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -899,8 +899,15 @@ static void test_CopyFileW(void) ok(!ret && GetLastError() == ERROR_FILE_EXISTS, "CopyFileW: unexpected error %ld\n", GetLastError());
+ SetLastError(0xdeadbeef); ret = CopyFileW(source, dest, FALSE); ok(ret, "CopyFileW: error %ld\n", GetLastError()); + ok(GetLastError() == ERROR_SUCCESS, "Unexpected error %lu.\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = CopyFileExW(source, dest, NULL, NULL, NULL, 0 ); + ok(ret, "CopyFileExW: error %ld\n", GetLastError()); + ok(GetLastError() == ERROR_SUCCESS, "Unexpected error %lu.\n", GetLastError());
ret = DeleteFileW(source); ok(ret, "DeleteFileW: error %ld\n", GetLastError()); diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c index faf8fa42969..0b1656ac4bf 100644 --- a/dlls/kernelbase/file.c +++ b/dlls/kernelbase/file.c @@ -588,6 +588,7 @@ done: HeapFree( GetProcessHeap(), 0, buffer ); CloseHandle( h1 ); CloseHandle( h2 ); + if (ret) SetLastError( 0 ); return ret; }
diff --git a/dlls/msvcp140/tests/msvcp140.c b/dlls/msvcp140/tests/msvcp140.c index 423c4c652b9..1df2f058424 100644 --- a/dlls/msvcp140/tests/msvcp140.c +++ b/dlls/msvcp140/tests/msvcp140.c @@ -1619,7 +1619,7 @@ static void test_Copy_file(void) SetLastError(0xdeadbeef); ret = p_Copy_file(L"wine_test_dir/f1", L"wine_test_dir/f3"); ok(ret == ERROR_SUCCESS, "Got unexpected ret %lu.\n", ret); - todo_wine ok(GetLastError() == ret, "Got unexpected err %lu.\n", GetLastError()); + ok(GetLastError() == ret, "Got unexpected err %lu.\n", GetLastError());
SetLastError(0xdeadbeef); ret = p_Copy_file(L"wine_test_dir/missing", L"wine_test_dir/f3");