From dc736dae6356f540a7828b75455c71ecd66abfb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Tue, 11 Jul 2017 12:30:15 +0200 Subject: [PATCH] msvcp140: Implement _File_size. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Dösinger Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcp140/msvcp140.spec | 2 +- dlls/msvcp140/tests/msvcp140.c | 56 ++++++++++++++++++++++++++++++++++ dlls/msvcp90/ios.c | 12 ++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/dlls/msvcp140/msvcp140.spec b/dlls/msvcp140/msvcp140.spec index 0216450fe7a..2d511682d01 100644 --- a/dlls/msvcp140/msvcp140.spec +++ b/dlls/msvcp140/msvcp140.spec @@ -3648,7 +3648,7 @@ @ extern _FNan _FNan @ stub _FSinh @ extern _FSnan _FSnan -@ stub _File_size +@ cdecl _File_size(wstr) @ cdecl -ret64 _Getcoll() _Getcoll @ cdecl _Getctype(ptr) _Getctype @ cdecl _Getcvt(ptr) _Getcvt diff --git a/dlls/msvcp140/tests/msvcp140.c b/dlls/msvcp140/tests/msvcp140.c index 7cb75f518e2..f5559805a01 100644 --- a/dlls/msvcp140/tests/msvcp140.c +++ b/dlls/msvcp140/tests/msvcp140.c @@ -152,6 +152,7 @@ static int (__cdecl *p__Schedule_chore)(_Threadpool_chore*); static int (__cdecl *p__Reschedule_chore)(const _Threadpool_chore*); static void (__cdecl *p__Release_chore)(_Threadpool_chore*); +static ULONGLONG (__cdecl *p_File_size)(WCHAR const *); static int (__cdecl *p_To_byte)(const WCHAR *src, char *dst); static int (__cdecl *p_To_wide)(const char *src, WCHAR *dst); @@ -216,6 +217,7 @@ static BOOL init(void) SET(p__Release_chore, "?_Release_chore@details@Concurrency@@YAXPAU_Threadpool_chore@12@@Z"); } + SET(p_File_size, "_File_size"); SET(p_To_byte, "_To_byte"); SET(p_To_wide, "_To_wide"); @@ -563,6 +565,59 @@ static void test_to_wide(void) } } +static void test_File_size(void) +{ + ULONGLONG val; + HANDLE file; + LARGE_INTEGER file_size; + WCHAR test_f1_W[] = {'w','i','n','e','_','t','e','s','t','_','d','i','r','/','f','1',0}; + WCHAR test_f2_W[] = {'w','i','n','e','_','t','e','s','t','_','d','i','r','/','f','2',0}; + WCHAR test_dir_W[] = {'w','i','n','e','_','t','e','s','t','_','d','i','r',0}; + WCHAR test_ne_W[] = {'w','i','n','e','_','t','e','s','t','_','d','i','r','/','n','e',0}; + WCHAR temp_path[MAX_PATH], origin_path[MAX_PATH]; + + memset(origin_path, 0, sizeof(origin_path)); + memset(origin_path, 0, sizeof(temp_path)); + GetCurrentDirectoryW(MAX_PATH, origin_path); + GetTempPathW(MAX_PATH, temp_path); + ok(SetCurrentDirectoryW(temp_path), "SetCurrentDirectoryW to temp_path failed\n"); + + CreateDirectoryW(test_dir_W, NULL); + + file = CreateFileW(test_f1_W, 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); + val = p_File_size(test_f1_W); + ok(val == 7, "file_size is %s\n", wine_dbgstr_longlong(val)); + + file = CreateFileW(test_f2_W, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); + ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n"); + CloseHandle(file); + val = p_File_size(test_f2_W); + ok(val == 0, "file_size is %s\n", wine_dbgstr_longlong(val)); + + val = p_File_size(test_dir_W); + ok(val == 0, "file_size is %s\n", wine_dbgstr_longlong(val)); + + errno = 0xdeadbeef; + val = p_File_size(test_ne_W); + ok(val == ~(ULONGLONG)0, "file_size is %s\n", wine_dbgstr_longlong(val)); + ok(errno == 0xdeadbeef, "errno = %d\n", errno); + + errno = 0xdeadbeef; + val = p_File_size(NULL); + ok(val == ~(ULONGLONG)0, "file_size is %s\n", wine_dbgstr_longlong(val)); + ok(errno == 0xdeadbeef, "errno = %d\n", errno); + + ok(DeleteFileW(test_f1_W), "expect wine_test_dir/f1 to exist\n"); + ok(DeleteFileW(test_f2_W), "expect wine_test_dir/f2 to exist\n"); + ok(RemoveDirectoryW(test_dir_W), "expect wine_test_dir to exist\n"); + ok(SetCurrentDirectoryW(origin_path), "SetCurrentDirectoryW to origin_path failed\n"); +} + START_TEST(msvcp140) { if(!init()) return; @@ -574,5 +629,6 @@ START_TEST(msvcp140) test_chore(); test_to_byte(); test_to_wide(); + test_File_size(); FreeLibrary(msvcp); } diff --git a/dlls/msvcp90/ios.c b/dlls/msvcp90/ios.c index 8e3376c9619..e3ba6487087 100644 --- a/dlls/msvcp90/ios.c +++ b/dlls/msvcp90/ios.c @@ -15471,6 +15471,18 @@ ULONGLONG __cdecl tr2_sys__File_size_wchar(WCHAR const* path) return ((ULONGLONG)(fad.nFileSizeHigh) << 32) + fad.nFileSizeLow; } +/* _File_size, msvcp140 version. Different error handling. */ +ULONGLONG __cdecl _File_size(WCHAR const* path) +{ + WIN32_FILE_ATTRIBUTE_DATA fad; + + TRACE("(%s)\n", debugstr_w(path)); + if(!GetFileAttributesExW(path, GetFileExInfoStandard, &fad)) + return ~(ULONGLONG)0; + + return ((ULONGLONG)(fad.nFileSizeHigh) << 32) + fad.nFileSizeLow; +} + /* ?_Equivalent@sys@tr2@std@@YAHPB_W0@Z */ /* ?_Equivalent@sys@tr2@std@@YAHPEB_W0@Z */ int __cdecl tr2_sys__Equivalent_wchar(WCHAR const* path1, WCHAR const* path2)