YongHao Hu : msvcp110: Add tr2_sys__Link implementation and test.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Jan 12 12:15:22 CST 2016


Module: wine
Branch: master
Commit: 7aeb1d3360eab3b957d2d2ea1df276a0843d8b2a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7aeb1d3360eab3b957d2d2ea1df276a0843d8b2a

Author: YongHao Hu <christopherwuy at gmail.com>
Date:   Mon Jan 11 21:56:02 2016 +0800

msvcp110: Add tr2_sys__Link implementation and test.

Signed-off-by: YongHao Hu <christopherwuy at gmail.com>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcp110/msvcp110.spec         |  4 +-
 dlls/msvcp120/msvcp120.spec         |  4 +-
 dlls/msvcp120/tests/msvcp120.c      | 90 +++++++++++++++++++++++++++++++++++++
 dlls/msvcp120_app/msvcp120_app.spec |  4 +-
 dlls/msvcp90/ios.c                  | 13 ++++++
 5 files changed, 109 insertions(+), 6 deletions(-)

diff --git a/dlls/msvcp110/msvcp110.spec b/dlls/msvcp110/msvcp110.spec
index 6c8aee4..1df4c55 100644
--- a/dlls/msvcp110/msvcp110.spec
+++ b/dlls/msvcp110/msvcp110.spec
@@ -1570,8 +1570,8 @@
 @ stub -arch=arm ?_Launch at _Pad@std@@QAAXPAU_Thrd_imp_t@@@Z
 @ stub -arch=i386 ?_Launch at _Pad@std@@QAEXPAU_Thrd_imp_t@@@Z
 @ stub -arch=win64 ?_Launch at _Pad@std@@QEAAXPEAU_Thrd_imp_t@@@Z
-@ stub -arch=win32 ?_Link at sys@tr2 at std@@YAHPBD0 at Z
-@ stub -arch=win64 ?_Link at sys@tr2 at std@@YAHPEBD0 at Z
+@ cdecl -arch=win32 ?_Link at sys@tr2 at std@@YAHPBD0 at Z(str str) tr2_sys__Link
+@ cdecl -arch=win64 ?_Link at sys@tr2 at std@@YAHPEBD0 at Z(str str) tr2_sys__Link
 @ stub -arch=win32 ?_Link at sys@tr2 at std@@YAHPB_W0 at Z
 @ stub -arch=win64 ?_Link at sys@tr2 at std@@YAHPEB_W0 at Z
 @ cdecl -arch=win32 ?_Locimp_Addfac at _Locimp@locale at std@@CAXPAV123 at PAVfacet@23 at I@Z(ptr ptr long) locale__Locimp__Locimp_Addfac
diff --git a/dlls/msvcp120/msvcp120.spec b/dlls/msvcp120/msvcp120.spec
index e3200a2..626ead8 100644
--- a/dlls/msvcp120/msvcp120.spec
+++ b/dlls/msvcp120/msvcp120.spec
@@ -1531,8 +1531,8 @@
 @ stub -arch=arm ?_Launch at _Pad@std@@QAAXPAU_Thrd_imp_t@@@Z
 @ stub -arch=i386 ?_Launch at _Pad@std@@QAEXPAU_Thrd_imp_t@@@Z
 @ stub -arch=win64 ?_Launch at _Pad@std@@QEAAXPEAU_Thrd_imp_t@@@Z
-@ stub -arch=win32 ?_Link at sys@tr2 at std@@YAHPBD0 at Z
-@ stub -arch=win64 ?_Link at sys@tr2 at std@@YAHPEBD0 at Z
+@ cdecl -arch=win32 ?_Link at sys@tr2 at std@@YAHPBD0 at Z(str str) tr2_sys__Link
+@ cdecl -arch=win64 ?_Link at sys@tr2 at std@@YAHPEBD0 at Z(str str) tr2_sys__Link
 @ stub -arch=win32 ?_Link at sys@tr2 at std@@YAHPB_W0 at Z
 @ stub -arch=win64 ?_Link at sys@tr2 at std@@YAHPEB_W0 at Z
 @ cdecl -arch=win32 ?_Locimp_Addfac at _Locimp@locale at std@@CAXPAV123 at PAVfacet@23 at I@Z(ptr ptr long) locale__Locimp__Locimp_Addfac
diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c
index 2724470..77a6050 100644
--- a/dlls/msvcp120/tests/msvcp120.c
+++ b/dlls/msvcp120/tests/msvcp120.c
@@ -132,6 +132,7 @@ static void (__cdecl *p_tr2_sys__Last_write_time_set)(char const*, __int64);
 static void* (__cdecl *p_tr2_sys__Open_dir)(char*, char const*, int *, enum file_type*);
 static char* (__cdecl *p_tr2_sys__Read_dir)(char*, void*, enum file_type*);
 static void (__cdecl *p_tr2_sys__Close_dir)(void*);
+static int (__cdecl *p_tr2_sys__Link)(char const*, char const*);
 
 /* thrd */
 typedef struct
@@ -265,6 +266,8 @@ static BOOL init(void)
                 "?_Read_dir at sys@tr2 at std@@YAPEADAEAY0BAE at DPEAXAEAW4file_type@123@@Z");
         SET(p_tr2_sys__Close_dir,
                 "?_Close_dir at sys@tr2 at std@@YAXPEAX at Z");
+        SET(p_tr2_sys__Link,
+                "?_Link at sys@tr2 at std@@YAHPEBD0 at Z");
         SET(p__Thrd_current,
                 "_Thrd_current");
     } else {
@@ -318,6 +321,8 @@ static BOOL init(void)
                 "?_Read_dir at sys@tr2 at std@@YAPADAAY0BAE at DPAXAAW4file_type@123@@Z");
         SET(p_tr2_sys__Close_dir,
                 "?_Close_dir at sys@tr2 at std@@YAXPAX at Z");
+        SET(p_tr2_sys__Link,
+                "?_Link at sys@tr2 at std@@YAHPBD0 at Z");
 #ifdef __i386__
         SET(p_i386_Thrd_current,
                 "_Thrd_current");
@@ -1319,6 +1324,90 @@ static void test_tr2_sys__dir_operation(void)
     ok(RemoveDirectoryA("tr2_test_dir"), "expect tr2_test_dir to exist\n");
 }
 
+static void test_tr2_sys__Link(void)
+{
+    int ret, i;
+    HANDLE file, h1, h2;
+    BY_HANDLE_FILE_INFORMATION info1, info2;
+    char temp_path[MAX_PATH], current_path[MAX_PATH];
+    LARGE_INTEGER file_size;
+    struct {
+        char const *existing_path;
+        char const *new_path;
+        MSVCP_bool fail_if_exists;
+        int last_error;
+    } tests[] = {
+        { "f1", "f1_link", TRUE, ERROR_SUCCESS },
+        { "f1", "tr2_test_dir\\f1_link", TRUE, ERROR_SUCCESS },
+        { "tr2_test_dir\\f1_link", "tr2_test_dir\\f1_link_link", TRUE, ERROR_SUCCESS },
+        { "tr2_test_dir", "dir_link", TRUE, ERROR_ACCESS_DENIED },
+        { NULL, "NULL_link", TRUE, ERROR_INVALID_PARAMETER },
+        { "f1", NULL, TRUE, ERROR_INVALID_PARAMETER },
+        { "not_exist", "not_exist_link", TRUE, ERROR_FILE_NOT_FOUND },
+        { "f1", "not_exist_dir\\f1_link", TRUE, ERROR_PATH_NOT_FOUND }
+    };
+
+    memset(current_path, 0, MAX_PATH);
+    GetCurrentDirectoryA(MAX_PATH, current_path);
+    memset(temp_path, 0, MAX_PATH);
+    GetTempPathA(MAX_PATH, temp_path);
+    ok(SetCurrentDirectoryA(temp_path), "SetCurrentDirectoryA to temp_path failed\n");
+
+    ret = p_tr2_sys__Make_dir("tr2_test_dir");
+    ok(ret == 1, "test_tr2_sys__Make_dir(): expect 1 got %d\n", ret);
+    file = CreateFileA("f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
+    file_size.QuadPart = 7;
+    ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
+    ok(SetEndOfFile(file), "SetEndOfFile failed\n");
+    CloseHandle(file);
+
+    for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
+        errno = 0xdeadbeef;
+        ret = p_tr2_sys__Link(tests[i].existing_path, tests[i].new_path);
+        ok(ret == tests[i].last_error, "tr2_sys__Link(): test %d expect: %d, got %d\n",
+                i+1, tests[i].last_error, ret);
+        ok(errno == 0xdeadbeef, "tr2_sys__Link(): test %d errno expect 0xdeadbeef, got %d\n", i+1, errno);
+        if(ret == ERROR_SUCCESS)
+            ok(p_tr2_sys__File_size(tests[i].existing_path) == p_tr2_sys__File_size(tests[i].new_path),
+                    "tr2_sys__Link(): test %d failed, two files' size are not equal\n", i+1);
+    }
+
+    ok(DeleteFileA("f1"), "expect f1 to exist\n");
+    ok(p_tr2_sys__File_size("f1_link") == p_tr2_sys__File_size("tr2_test_dir/f1_link") &&
+            p_tr2_sys__File_size("tr2_test_dir/f1_link") == p_tr2_sys__File_size("tr2_test_dir/f1_link_link"),
+            "tr2_sys__Link(): expect links' size are equal, got %s\n", debugstr_longlong(p_tr2_sys__File_size("tr2_test_dir/f1_link_link")));
+    ok(p_tr2_sys__File_size("f1_link") == 7, "tr2_sys__Link(): expect f1_link's size equals to 7, got %s\n", debugstr_longlong(p_tr2_sys__File_size("f1_link")));
+
+    file = CreateFileA("f1_link", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
+    file_size.QuadPart = 20;
+    ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
+    ok(SetEndOfFile(file), "SetEndOfFile failed\n");
+    CloseHandle(file);
+    h1 = CreateFileA("f1_link", 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
+            NULL, OPEN_EXISTING, 0, 0);
+    ok(h1 != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
+    ok(GetFileInformationByHandle(h1, &info1), "GetFileInformationByHandle failed\n");
+    CloseHandle(h1);
+    h2 = CreateFileA("tr2_test_dir/f1_link", 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
+            NULL, OPEN_EXISTING, 0, 0);
+    ok(h2 != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
+    ok(GetFileInformationByHandle(h2, &info2), "GetFileInformationByHandle failed\n");
+    CloseHandle(h2);
+    ok(info1.nFileIndexHigh == info2.nFileIndexHigh
+            && info1.nFileIndexLow == info2.nFileIndexLow,
+            "tr2_sys__Link(): test %d expect two files equivalent\n", i+1);
+    ok(p_tr2_sys__File_size("f1_link") == 20, "tr2_sys__Link(): expect f1_link's size equals to 20, got %s\n", debugstr_longlong(p_tr2_sys__File_size("f1_link")));
+
+    ok(DeleteFileA("f1_link"), "expect f1_link to exist\n");
+    ok(DeleteFileA("tr2_test_dir/f1_link"), "expect tr2_test_dir/f1_link to exist\n");
+    ok(DeleteFileA("tr2_test_dir/f1_link_link"), "expect tr2_test_dir/f1_link_link to exist\n");
+    ret = p_tr2_sys__Remove_dir("tr2_test_dir");
+    ok(ret == 1, "tr2_sys__Remove_dir(): expect 1 got %d\n", ret);
+    ok(SetCurrentDirectoryA(current_path), "SetCurrentDirectoryA failed\n");
+}
+
 static int __cdecl thrd_thread(void *arg)
 {
     _Thrd_t *thr = arg;
@@ -1608,6 +1697,7 @@ START_TEST(msvcp120)
     test_tr2_sys__Stat();
     test_tr2_sys__Last_write_time();
     test_tr2_sys__dir_operation();
+    test_tr2_sys__Link();
 
     test_thrd();
     test_cnd();
diff --git a/dlls/msvcp120_app/msvcp120_app.spec b/dlls/msvcp120_app/msvcp120_app.spec
index 655e0e6..517e1b0 100644
--- a/dlls/msvcp120_app/msvcp120_app.spec
+++ b/dlls/msvcp120_app/msvcp120_app.spec
@@ -1531,8 +1531,8 @@
 @ stub -arch=arm ?_Launch at _Pad@std@@QAAXPAU_Thrd_imp_t@@@Z
 @ stub -arch=i386 ?_Launch at _Pad@std@@QAEXPAU_Thrd_imp_t@@@Z
 @ stub -arch=win64 ?_Launch at _Pad@std@@QEAAXPEAU_Thrd_imp_t@@@Z
-@ stub -arch=win32 ?_Link at sys@tr2 at std@@YAHPBD0 at Z
-@ stub -arch=win64 ?_Link at sys@tr2 at std@@YAHPEBD0 at Z
+@ cdecl -arch=win32 ?_Link at sys@tr2 at std@@YAHPBD0 at Z(str str) msvcp120.?_Link at sys@tr2 at std@@YAHPBD0 at Z
+@ cdecl -arch=win64 ?_Link at sys@tr2 at std@@YAHPEBD0 at Z(str str) msvcp120.?_Link at sys@tr2 at std@@YAHPEBD0 at Z
 @ stub -arch=win32 ?_Link at sys@tr2 at std@@YAHPB_W0 at Z
 @ stub -arch=win64 ?_Link at sys@tr2 at std@@YAHPEB_W0 at Z
 @ cdecl -arch=win32 ?_Locimp_Addfac at _Locimp@locale at std@@CAXPAV123 at PAVfacet@23 at I@Z(ptr ptr long) msvcp120.?_Locimp_Addfac at _Locimp@locale at std@@CAXPAV123 at PAVfacet@23 at I@Z
diff --git a/dlls/msvcp90/ios.c b/dlls/msvcp90/ios.c
index c190ce4..12e2984 100644
--- a/dlls/msvcp90/ios.c
+++ b/dlls/msvcp90/ios.c
@@ -14756,6 +14756,19 @@ void __cdecl tr2_sys__Close_dir(void* handle)
     FindClose(handle);
 }
 
+/* ?_Link at sys@tr2 at std@@YAHPBD0 at Z */
+/* ?_Link at sys@tr2 at std@@YAHPEBD0 at Z */
+int __cdecl tr2_sys__Link(char const* existing_path, char const* new_path)
+{
+    TRACE("(%s %s)\n", debugstr_a(existing_path), debugstr_a(new_path));
+    if(!existing_path || !new_path)
+        return ERROR_INVALID_PARAMETER;
+
+    if(CreateHardLinkA(new_path, existing_path, NULL))
+        return ERROR_SUCCESS;
+    return GetLastError();
+}
+
 /* ??0strstream at std@@QAE at PADHH@Z */
 /* ??0strstream at std@@QEAA at PEAD_JH@Z */
 #if STREAMSIZE_BITS == 64




More information about the wine-cvs mailing list