Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/msvcp140/msvcp140.spec | 2 +- dlls/msvcp140/tests/msvcp140.c | 62 ++++++++++++++++++++++++++++++++++ dlls/msvcp90/ios.c | 13 +++++++ dlls/msvcp_win/msvcp_win.spec | 2 +- 4 files changed, 77 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..1df2f058424 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); + 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..34d05608047 100644 --- a/dlls/msvcp90/ios.c +++ b/dlls/msvcp90/ios.c @@ -15776,6 +15776,19 @@ 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)) + { + SetLastError(ERROR_SUCCESS); + 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
Hi Paul,
On 4/11/22 19:13, Paul Gofman wrote:
+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))
- {
SetLastError(ERROR_SUCCESS);
It looks like the SetLastError call is only needed because of a bug in CopyFileW implementation. Please remove it and mark the test as todo_wine or fix CopyFileW.
Thanks, Piotr