msvcp110: Add tr2_sys__Last_write_time implementation and test.

This commit is contained in:
YongHao Hu 2015-09-19 08:43:31 +08:00 committed by Alexandre Julliard
parent 24d57405ac
commit a6dc6ac4ff
8 changed files with 241 additions and 12 deletions

1
configure vendored
View File

@ -17591,6 +17591,7 @@ wine_fn_config_dll msvcm90 enable_msvcm90
wine_fn_config_dll msvcp100 enable_msvcp100
wine_fn_config_test dlls/msvcp100/tests msvcp100_test
wine_fn_config_dll msvcp110 enable_msvcp110
wine_fn_config_test dlls/msvcp110/tests msvcp110_test
wine_fn_config_dll msvcp120 enable_msvcp120
wine_fn_config_test dlls/msvcp120/tests msvcp120_test
wine_fn_config_dll msvcp120_app enable_msvcp120_app

View File

@ -3142,6 +3142,7 @@ WINE_CONFIG_DLL(msvcm90)
WINE_CONFIG_DLL(msvcp100)
WINE_CONFIG_TEST(dlls/msvcp100/tests)
WINE_CONFIG_DLL(msvcp110)
WINE_CONFIG_TEST(dlls/msvcp110/tests)
WINE_CONFIG_DLL(msvcp120)
WINE_CONFIG_TEST(dlls/msvcp120/tests)
WINE_CONFIG_DLL(msvcp120_app)

View File

@ -1559,12 +1559,12 @@
@ cdecl -arch=win64 ?_Iput@?$num_put@GV?$ostreambuf_iterator@GU?$char_traits@G@std@@@std@@@std@@AEBA?AV?$ostreambuf_iterator@GU?$char_traits@G@std@@@2@V32@AEAVios_base@2@GPEAD_K@Z(ptr ptr ptr ptr long ptr long) num_put_short__Iput
@ cdecl -arch=win32 ?_Iput@?$num_put@_WV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@std@@@std@@ABA?AV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@2@V32@AAVios_base@2@_WPADI@Z(ptr ptr long ptr ptr long ptr long) num_put_wchar__Iput
@ cdecl -arch=win64 ?_Iput@?$num_put@_WV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@std@@@std@@AEBA?AV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@2@V32@AEAVios_base@2@_WPEAD_K@Z(ptr ptr ptr ptr long ptr long) num_put_wchar__Iput
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z
@ cdecl -arch=win32 ?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z(str int64) tr2_sys__Last_write_time_set
@ cdecl -arch=win64 ?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z(str int64) tr2_sys__Last_write_time_set
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YAXPB_W_J@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YAXPEB_W_J@Z
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YA_JPBD@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z
@ cdecl -ret64 -arch=win32 ?_Last_write_time@sys@tr2@std@@YA_JPBD@Z(str) tr2_sys__Last_write_time
@ cdecl -ret64 -arch=win64 ?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z(str) tr2_sys__Last_write_time
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YA_JPB_W@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YA_JPEB_W@Z
@ stub -arch=arm ?_Launch@_Pad@std@@QAAXPAU_Thrd_imp_t@@@Z

View File

@ -0,0 +1,5 @@
TESTDLL = msvcp110.dll
APPMODE = -mno-cygwin
C_SRCS = \
msvcp110.c

View File

@ -0,0 +1,163 @@
/*
* Copyright 2015 YongHao Hu
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <locale.h>
#include <stdio.h>
#include "wine/test.h"
#include "winbase.h"
typedef unsigned char MSVCP_bool;
#define SECSPERDAY 86400
/* 1601 to 1970 is 369 years plus 89 leap days */
#define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
#define TICKSPERSEC 10000000
#define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
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 int (__cdecl *p_tr2_sys__Make_dir)(char const*);
static MSVCP_bool (__cdecl *p_tr2_sys__Remove_dir)(char const*);
static __int64 (__cdecl *p_tr2_sys__Last_write_time)(char const*);
static void (__cdecl *p_tr2_sys__Last_write_time_set)(char const*, __int64);
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)
{
msvcp = LoadLibraryA("msvcp110.dll");
if(!msvcp)
{
win_skip("msvcp110.dll not installed\n");
return FALSE;
}
if(sizeof(void*) == 8) { /* 64-bit initialization */
SET(p_tr2_sys__Make_dir,
"?_Make_dir@sys@tr2@std@@YAHPEBD@Z");
SET(p_tr2_sys__Remove_dir,
"?_Remove_dir@sys@tr2@std@@YA_NPEBD@Z");
SET(p_tr2_sys__Last_write_time,
"?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z");
SET(p_tr2_sys__Last_write_time_set,
"?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z");
} else {
SET(p_tr2_sys__Make_dir,
"?_Make_dir@sys@tr2@std@@YAHPBD@Z");
SET(p_tr2_sys__Remove_dir,
"?_Remove_dir@sys@tr2@std@@YA_NPBD@Z");
SET(p_tr2_sys__Last_write_time,
"?_Last_write_time@sys@tr2@std@@YA_JPBD@Z");
SET(p_tr2_sys__Last_write_time_set,
"?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z");
}
return TRUE;
}
static void test_tr2_sys__Last_write_time(void)
{
HANDLE file;
int ret;
FILETIME lwt;
__int64 last_write_time, newtime, margin_of_error = 10 * TICKSPERSEC;
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("tr2_test_dir/f1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed: INVALID_HANDLE_VALUE\n");
CloseHandle(file);
last_write_time = p_tr2_sys__Last_write_time("tr2_test_dir/f1");
newtime = last_write_time + 222222;
p_tr2_sys__Last_write_time_set("tr2_test_dir/f1", newtime);
ok(last_write_time != p_tr2_sys__Last_write_time("tr2_test_dir/f1"),
"last_write_time before modfied should not equal to last_write_time %s\n",
debugstr_longlong(last_write_time));
/* test the formula */
file = CreateFileA("tr2_test_dir/f1", 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
ok(GetFileTime(file, 0, 0, &lwt), "GetFileTime failed\n");
CloseHandle(file);
last_write_time = (((__int64)lwt.dwHighDateTime)<< 32) + lwt.dwLowDateTime;
last_write_time -= TICKS_1601_TO_1970;
last_write_time /= TICKSPERSEC;
ok(newtime-margin_of_error<=last_write_time && last_write_time<=newtime+margin_of_error,
"don't fit the formula, last_write_time is %s\n", debugstr_longlong(last_write_time));
newtime = 0;
p_tr2_sys__Last_write_time_set("tr2_test_dir/f1", newtime);
newtime = p_tr2_sys__Last_write_time("tr2_test_dir/f1");
file = CreateFileA("tr2_test_dir/f1", 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
ok(GetFileTime(file, 0, 0, &lwt), "GetFileTime failed\n");
CloseHandle(file);
last_write_time = (((__int64)lwt.dwHighDateTime)<< 32) + lwt.dwLowDateTime;
last_write_time -= TICKS_1601_TO_1970;
last_write_time /= TICKSPERSEC;
ok(newtime-margin_of_error<=last_write_time && last_write_time<=newtime+margin_of_error,
"don't fit the formula, last_write_time is %s\n", debugstr_longlong(last_write_time));
newtime = 123456789;
p_tr2_sys__Last_write_time_set("tr2_test_dir/f1", newtime);
newtime = p_tr2_sys__Last_write_time("tr2_test_dir/f1");
file = CreateFileA("tr2_test_dir/f1", 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
ok(file != INVALID_HANDLE_VALUE, "create file failed: INVALID_HANDLE_VALUE\n");
ok(GetFileTime(file, 0, 0, &lwt), "GetFileTime failed\n");
CloseHandle(file);
last_write_time = (((__int64)lwt.dwHighDateTime)<< 32) + lwt.dwLowDateTime;
last_write_time -= TICKS_1601_TO_1970;
last_write_time /= TICKSPERSEC;
ok(newtime-margin_of_error<=last_write_time && last_write_time<=newtime+margin_of_error,
"don't fit the formula, last_write_time is %s\n", debugstr_longlong(last_write_time));
errno = 0xdeadbeef;
last_write_time = p_tr2_sys__Last_write_time("not_exist");
ok(errno == 0xdeadbeef, "tr2_sys__Last_write_time(): errno expect 0xdeadbeef, got %d\n", errno);
ok(last_write_time == 0, "expect 0 got %s\n", debugstr_longlong(last_write_time));
last_write_time = p_tr2_sys__Last_write_time(NULL);
ok(last_write_time == 0, "expect 0 got %s\n", debugstr_longlong(last_write_time));
p_tr2_sys__Last_write_time_set("not_exist", newtime);
errno = 0xdeadbeef;
p_tr2_sys__Last_write_time_set(NULL, newtime);
ok(errno == 0xdeadbeef, "tr2_sys__Last_write_time(): errno expect 0xdeadbeef, got %d\n", errno);
ok(DeleteFileA("tr2_test_dir/f1"), "expect tr2_test_dir/f1 to exist\n");
ret = p_tr2_sys__Remove_dir("tr2_test_dir");
ok(ret == 1, "test_tr2_sys__Remove_dir(): expect 1 got %d\n", ret);
}
START_TEST(msvcp110)
{
if(!init()) return;
test_tr2_sys__Last_write_time();
FreeLibrary(msvcp);
}

View File

@ -1520,12 +1520,12 @@
@ cdecl -arch=win64 ?_Iput@?$num_put@GV?$ostreambuf_iterator@GU?$char_traits@G@std@@@std@@@std@@AEBA?AV?$ostreambuf_iterator@GU?$char_traits@G@std@@@2@V32@AEAVios_base@2@GPEAD_K@Z(ptr ptr ptr ptr long ptr long) num_put_short__Iput
@ cdecl -arch=win32 ?_Iput@?$num_put@_WV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@std@@@std@@ABA?AV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@2@V32@AAVios_base@2@_WPADI@Z(ptr ptr long ptr ptr long ptr long) num_put_wchar__Iput
@ cdecl -arch=win64 ?_Iput@?$num_put@_WV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@std@@@std@@AEBA?AV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@2@V32@AEAVios_base@2@_WPEAD_K@Z(ptr ptr ptr ptr long ptr long) num_put_wchar__Iput
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z
@ cdecl -arch=win32 ?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z(str int64) tr2_sys__Last_write_time_set
@ cdecl -arch=win64 ?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z(str int64) tr2_sys__Last_write_time_set
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YAXPB_W_J@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YAXPEB_W_J@Z
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YA_JPBD@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z
@ cdecl -ret64 -arch=win32 ?_Last_write_time@sys@tr2@std@@YA_JPBD@Z(str) tr2_sys__Last_write_time
@ cdecl -ret64 -arch=win64 ?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z(str) tr2_sys__Last_write_time
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YA_JPB_W@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YA_JPEB_W@Z
@ stub -arch=arm ?_Launch@_Pad@std@@QAAXPAU_Thrd_imp_t@@@Z

View File

@ -1520,12 +1520,12 @@
@ cdecl -arch=win64 ?_Iput@?$num_put@GV?$ostreambuf_iterator@GU?$char_traits@G@std@@@std@@@std@@AEBA?AV?$ostreambuf_iterator@GU?$char_traits@G@std@@@2@V32@AEAVios_base@2@GPEAD_K@Z(ptr ptr ptr ptr long ptr long) msvcp120.?_Iput@?$num_put@GV?$ostreambuf_iterator@GU?$char_traits@G@std@@@std@@@std@@AEBA?AV?$ostreambuf_iterator@GU?$char_traits@G@std@@@2@V32@AEAVios_base@2@GPEAD_K@Z
@ cdecl -arch=win32 ?_Iput@?$num_put@_WV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@std@@@std@@ABA?AV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@2@V32@AAVios_base@2@_WPADI@Z(ptr ptr long ptr ptr long ptr long) msvcp120.?_Iput@?$num_put@_WV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@std@@@std@@ABA?AV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@2@V32@AAVios_base@2@_WPADI@Z
@ cdecl -arch=win64 ?_Iput@?$num_put@_WV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@std@@@std@@AEBA?AV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@2@V32@AEAVios_base@2@_WPEAD_K@Z(ptr ptr ptr ptr long ptr long) msvcp120.?_Iput@?$num_put@_WV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@std@@@std@@AEBA?AV?$ostreambuf_iterator@_WU?$char_traits@_W@std@@@2@V32@AEAVios_base@2@_WPEAD_K@Z
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z
@ cdecl -arch=win32 ?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z(str int64) msvcp120.?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z
@ cdecl -arch=win64 ?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z(str int64) msvcp120.?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YAXPB_W_J@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YAXPEB_W_J@Z
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YA_JPBD@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z
@ cdecl -ret64 -arch=win32 ?_Last_write_time@sys@tr2@std@@YA_JPBD@Z(str) msvcp120.?_Last_write_time@sys@tr2@std@@YA_JPBD@Z
@ cdecl -ret64 -arch=win64 ?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z(str) msvcp120.?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z
@ stub -arch=win32 ?_Last_write_time@sys@tr2@std@@YA_JPB_W@Z
@ stub -arch=win64 ?_Last_write_time@sys@tr2@std@@YA_JPEB_W@Z
@ stub -arch=arm ?_Launch@_Pad@std@@QAAXPAU_Thrd_imp_t@@@Z

View File

@ -29,6 +29,12 @@
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
#define SECSPERDAY 86400
/* 1601 to 1970 is 369 years plus 89 leap days */
#define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
#define TICKSPERSEC 10000000
#define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
/* ?_Index@ios_base@std@@0HA */
int ios_base_Index = 0;
/* ?_Sync@ios_base@std@@0_NA */
@ -14380,6 +14386,59 @@ enum file_type __cdecl tr2_sys__Lstat(char const* path, int* err_code)
return tr2_sys__Stat(path, err_code);
}
/* ?_Last_write_time@sys@tr2@std@@YA_JPBD@Z */
/* ?_Last_write_time@sys@tr2@std@@YA_JPEBD@Z */
__int64 __cdecl tr2_sys__Last_write_time(char const* path)
{
HANDLE handle;
FILETIME lwt;
int ret;
__int64 last_write_time;
TRACE("(%s)\n", debugstr_a(path));
handle = CreateFileA(path, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
if(handle == INVALID_HANDLE_VALUE)
return 0;
ret = GetFileTime(handle, 0, 0, &lwt);
CloseHandle(handle);
if(!ret)
return 0;
last_write_time = (((__int64)lwt.dwHighDateTime)<< 32) + lwt.dwLowDateTime;
last_write_time -= TICKS_1601_TO_1970;
last_write_time /= TICKSPERSEC;
return last_write_time;
}
/* ?_Last_write_time@sys@tr2@std@@YAXPBD_J@Z */
/* ?_Last_write_time@sys@tr2@std@@YAXPEBD_J@Z */
void __cdecl tr2_sys__Last_write_time_set(char const* path, __int64 newtime)
{
HANDLE handle;
FILETIME lwt;
TRACE("(%s)\n", debugstr_a(path));
handle = CreateFileA(path, FILE_WRITE_ATTRIBUTES,
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
if(handle == INVALID_HANDLE_VALUE)
return;
/* This is the implementation based on the test of msvcp110.
* According to the test of msvcp120,
* msvcp120's implementation does nothing. Obviously, this is a bug of windows.
*/
newtime *= TICKSPERSEC;
newtime += TICKS_1601_TO_1970;
lwt.dwLowDateTime = (DWORD)(newtime);
lwt.dwHighDateTime = (DWORD)(newtime >> 32);
SetFileTime(handle, 0, 0, &lwt);
CloseHandle(handle);
}
/* ??0strstream@std@@QAE@PADHH@Z */
/* ??0strstream@std@@QEAA@PEAD_JH@Z */
#if STREAMSIZE_BITS == 64