YongHao Hu : msvcp110: Add tr2_sys__File_size implementation and test.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jun 15 08:49:09 CDT 2015


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

Author: YongHao Hu <christopherwuy at gmail.com>
Date:   Sat Jun 13 00:28:39 2015 +0800

msvcp110: Add tr2_sys__File_size implementation and test.

---

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

diff --git a/dlls/msvcp110/msvcp110.spec b/dlls/msvcp110/msvcp110.spec
index 86eaa75..5c48c76 100644
--- a/dlls/msvcp110/msvcp110.spec
+++ b/dlls/msvcp110/msvcp110.spec
@@ -1206,8 +1206,8 @@
 @ cdecl -arch=win64 ?_Ffmt@?$num_put at GV?$ostreambuf_iterator at GU?$char_traits at G@std@@@std@@@std@@AEBAPEADPEADDH at Z(ptr ptr long long) num_put_wchar__Ffmt
 @ cdecl -arch=win32 ?_Ffmt@?$num_put at _WV?$ostreambuf_iterator at _WU?$char_traits at _W@std@@@std@@@std@@ABAPADPADDH at Z(ptr ptr long long) num_put_wchar__Ffmt
 @ cdecl -arch=win64 ?_Ffmt@?$num_put at _WV?$ostreambuf_iterator at _WU?$char_traits at _W@std@@@std@@@std@@AEBAPEADPEADDH at Z(ptr ptr long long) num_put_wchar__Ffmt
-@ stub -arch=win32 ?_File_size at sys@tr2 at std@@YA_KPBD at Z
-@ stub -arch=win64 ?_File_size at sys@tr2 at std@@YA_KPEBD at Z
+@ cdecl -ret64 -arch=win32 ?_File_size at sys@tr2 at std@@YA_KPBD at Z(str) tr2_sys__File_size
+@ cdecl -ret64 -arch=win64 ?_File_size at sys@tr2 at std@@YA_KPEBD at Z(str) tr2_sys__File_size
 @ stub -arch=win32 ?_File_size at sys@tr2 at std@@YA_KPB_W at Z
 @ stub -arch=win64 ?_File_size at sys@tr2 at std@@YA_KPEB_W at Z
 @ cdecl -arch=arm ?_Findarr at ios_base@std@@AAAAAU_Iosarray at 12@H at Z(ptr long) ios_base_Findarr
diff --git a/dlls/msvcp120/msvcp120.spec b/dlls/msvcp120/msvcp120.spec
index ef42168..a6e60b1 100644
--- a/dlls/msvcp120/msvcp120.spec
+++ b/dlls/msvcp120/msvcp120.spec
@@ -1171,8 +1171,8 @@
 @ cdecl -arch=win64 ?_Ffmt@?$num_put at GV?$ostreambuf_iterator at GU?$char_traits at G@std@@@std@@@std@@AEBAPEADPEADDH at Z(ptr ptr long long) num_put_wchar__Ffmt
 @ cdecl -arch=win32 ?_Ffmt@?$num_put at _WV?$ostreambuf_iterator at _WU?$char_traits at _W@std@@@std@@@std@@ABAPADPADDH at Z(ptr ptr long long) num_put_wchar__Ffmt
 @ cdecl -arch=win64 ?_Ffmt@?$num_put at _WV?$ostreambuf_iterator at _WU?$char_traits at _W@std@@@std@@@std@@AEBAPEADPEADDH at Z(ptr ptr long long) num_put_wchar__Ffmt
-@ stub -arch=win32 ?_File_size at sys@tr2 at std@@YA_KPBD at Z
-@ stub -arch=win64 ?_File_size at sys@tr2 at std@@YA_KPEBD at Z
+@ cdecl -ret64 -arch=win32 ?_File_size at sys@tr2 at std@@YA_KPBD at Z(str) tr2_sys__File_size
+@ cdecl -ret64 -arch=win64 ?_File_size at sys@tr2 at std@@YA_KPEBD at Z(str) tr2_sys__File_size
 @ stub -arch=win32 ?_File_size at sys@tr2 at std@@YA_KPB_W at Z
 @ stub -arch=win64 ?_File_size at sys@tr2 at std@@YA_KPEB_W at Z
 @ cdecl -arch=arm ?_Findarr at ios_base@std@@AAAAAU_Iosarray at 12@H at Z(ptr long) ios_base_Findarr
diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c
index 5db2fa0..41e4c56 100644
--- a/dlls/msvcp120/tests/msvcp120.c
+++ b/dlls/msvcp120/tests/msvcp120.c
@@ -17,6 +17,7 @@
  */
 
 #include <locale.h>
+#include <stdio.h>
 
 #include "wine/test.h"
 #include "winbase.h"
@@ -36,6 +37,16 @@ typedef struct {
     BYTE isleadbyte[32];
 } _Cvtvec;
 
+static inline const char* debugstr_longlong(ULONGLONG ll)
+{
+    static char string[17];
+    if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
+        sprintf(string, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll);
+    else
+        sprintf(string, "%lx", (unsigned long)ll);
+    return string;
+}
+
 static char* (__cdecl *p_setlocale)(int, const char*);
 static int (__cdecl *p__setmbcp)(int);
 static int (__cdecl *p_isleadbyte)(int);
@@ -47,8 +58,12 @@ static void (CDECL *p__Call_once)(int *once, void (CDECL *func)(void));
 static void (CDECL *p__Call_onceEx)(int *once, void (CDECL *func)(void*), void *argv);
 static void (CDECL *p__Do_call)(void *this);
 
-static HMODULE msvcp;
+/* filesystem */
+static ULONGLONG(__cdecl *p_tr2_sys__File_size)(char const*);
 
+static HMODULE msvcp;
+#define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
+#define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
 static BOOL init(void)
 {
     HANDLE msvcr;
@@ -60,12 +75,25 @@ static BOOL init(void)
         return FALSE;
     }
 
-    p__Xtime_diff_to_millis2 = (void*)GetProcAddress(msvcp, "_Xtime_diff_to_millis2");
-    p_xtime_get = (void*)GetProcAddress(msvcp, "xtime_get");
-    p__Getcvt = (void*)GetProcAddress(msvcp, "_Getcvt");
-    p__Call_once = (void*)GetProcAddress(msvcp, "_Call_once");
-    p__Call_onceEx = (void*)GetProcAddress(msvcp, "_Call_onceEx");
-    p__Do_call = (void*)GetProcAddress(msvcp, "_Do_call");
+    SET(p__Xtime_diff_to_millis2,
+            "_Xtime_diff_to_millis2");
+    SET(p_xtime_get,
+            "xtime_get");
+    SET(p__Getcvt,
+            "_Getcvt");
+    SET(p__Call_once,
+            "_Call_once");
+    SET(p__Call_onceEx,
+            "_Call_onceEx");
+    SET(p__Do_call,
+            "_Do_call");
+    if(sizeof(void*) == 8) { /* 64-bit initialization */
+        SET(p_tr2_sys__File_size,
+                "?_File_size at sys@tr2 at std@@YA_KPEBD at Z");
+    } else {
+        SET(p_tr2_sys__File_size,
+                "?_File_size at sys@tr2 at std@@YA_KPBD at Z");
+    }
 
     msvcr = GetModuleHandleA("msvcr120.dll");
     p_setlocale = (void*)GetProcAddress(msvcr, "setlocale");
@@ -271,6 +299,45 @@ static void test__Do_call(void)
     ok(cnt == 1, "func was not called\n");
 }
 
+static void test_tr2_sys__File_size(void)
+{
+    ULONGLONG val;
+    HANDLE file;
+    LARGE_INTEGER file_size = {{7, 0}};
+    CreateDirectoryA("tr2_test_dir", NULL);
+
+    file = CreateFileA("tr2_test_dir/f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
+    ok(SetFilePointerEx(file, file_size, NULL, FILE_BEGIN), "SetFilePointerEx failed\n");
+    ok(SetEndOfFile(file), "SetEndOfFile failed\n");
+    CloseHandle(file);
+    val = p_tr2_sys__File_size("tr2_test_dir/f1");
+    ok(val == 7, "file_size is %s\n", debugstr_longlong(val));
+
+    file = CreateFileA("tr2_test_dir/f2", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+    ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
+    CloseHandle(file);
+    val = p_tr2_sys__File_size("tr2_test_dir/f2");
+    ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
+
+    val = p_tr2_sys__File_size("tr2_test_dir");
+    ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
+
+    errno = 0xdeadbeef;
+    val = p_tr2_sys__File_size("tr2_test_dir/not_exists_file");
+    ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
+    ok(errno == 0xdeadbeef, "errno = %d\n", errno);
+
+    errno = 0xdeadbeef;
+    val = p_tr2_sys__File_size(NULL);
+    ok(val == 0, "file_size is %s\n", debugstr_longlong(val));
+    ok(errno == 0xdeadbeef, "errno = %d\n", errno);
+
+    ok(DeleteFileA("tr2_test_dir/f1"), "Expected tr2_test_dir/f1 to exist\n");
+    ok(DeleteFileA("tr2_test_dir/f2"), "Expected tr2_test_dir/f2 to exist\n");
+    ok(RemoveDirectoryA("tr2_test_dir"), "Expected tr2_test_dir to exist\n");
+}
+
 START_TEST(msvcp120)
 {
     if(!init()) return;
@@ -280,5 +347,6 @@ START_TEST(msvcp120)
     test__Call_once();
     test__Do_call();
 
+    test_tr2_sys__File_size();
     FreeLibrary(msvcp);
 }
diff --git a/dlls/msvcp120_app/msvcp120_app.spec b/dlls/msvcp120_app/msvcp120_app.spec
index 2c409b1..e317987 100644
--- a/dlls/msvcp120_app/msvcp120_app.spec
+++ b/dlls/msvcp120_app/msvcp120_app.spec
@@ -1171,8 +1171,8 @@
 @ cdecl -arch=win64 ?_Ffmt@?$num_put at GV?$ostreambuf_iterator at GU?$char_traits at G@std@@@std@@@std@@AEBAPEADPEADDH at Z(ptr ptr long long) msvcp120.?_Ffmt@?$num_put at GV?$ostreambuf_iterator at GU?$char_traits at G@std@@@std@@@std@@AEBAPEADPEADDH at Z
 @ cdecl -arch=win32 ?_Ffmt@?$num_put at _WV?$ostreambuf_iterator at _WU?$char_traits at _W@std@@@std@@@std@@ABAPADPADDH at Z(ptr ptr long long) msvcp120.?_Ffmt@?$num_put at _WV?$ostreambuf_iterator at _WU?$char_traits at _W@std@@@std@@@std@@ABAPADPADDH at Z
 @ cdecl -arch=win64 ?_Ffmt@?$num_put at _WV?$ostreambuf_iterator at _WU?$char_traits at _W@std@@@std@@@std@@AEBAPEADPEADDH at Z(ptr ptr long long) msvcp120.?_Ffmt@?$num_put at _WV?$ostreambuf_iterator at _WU?$char_traits at _W@std@@@std@@@std@@AEBAPEADPEADDH at Z
-@ stub -arch=win32 ?_File_size at sys@tr2 at std@@YA_KPBD at Z
-@ stub -arch=win64 ?_File_size at sys@tr2 at std@@YA_KPEBD at Z
+@ cdecl -ret64 -arch=win32 ?_File_size at sys@tr2 at std@@YA_KPBD at Z(str) msvcp120.?_File_size at sys@tr2 at std@@YA_KPBD at Z
+@ cdecl -ret64 -arch=win64 ?_File_size at sys@tr2 at std@@YA_KPEBD at Z(str) msvcp120.?_File_size at sys@tr2 at std@@YA_KPEBD at Z
 @ stub -arch=win32 ?_File_size at sys@tr2 at std@@YA_KPB_W at Z
 @ stub -arch=win64 ?_File_size at sys@tr2 at std@@YA_KPEB_W at Z
 @ cdecl -arch=arm ?_Findarr at ios_base@std@@AAAAAU_Iosarray at 12@H at Z(ptr long) msvcp120.?_Findarr at ios_base@std@@AAAAAU_Iosarray at 12@H at Z
diff --git a/dlls/msvcp90/ios.c b/dlls/msvcp90/ios.c
index a15bed6..7b8e226 100644
--- a/dlls/msvcp90/ios.c
+++ b/dlls/msvcp90/ios.c
@@ -14190,6 +14190,21 @@ basic_ostream_char* __cdecl basic_ostream_char_print_complex_ldouble(basic_ostre
     return ostr;
 }
 
+/* ?_File_size at sys@tr2 at std@@YA_KPBD at Z  */
+/* ?_File_size at sys@tr2 at std@@YA_KPEBD at Z */
+ULONGLONG __cdecl tr2_sys__File_size(const char* path)
+{
+    WIN32_FILE_ATTRIBUTE_DATA fad;
+
+    TRACE("(%p)\n", path);
+    if(!GetFileAttributesExA(path, GetFileExInfoStandard, &fad))
+        return 0;
+    if(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+        return 0;
+
+    return ((ULONGLONG)(fad.nFileSizeHigh) << 32) + fad.nFileSizeLow;
+}
+
 /* ??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