kernel32: Reimplement DosDateTimeToFileTime/FileTimeToDosDateTime using ntdll functions.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
feature/deterministic
Alexandre Julliard 2020-05-26 14:05:10 +02:00
parent fc173ccca8
commit b6a38ea676
5 changed files with 49 additions and 83 deletions

3
configure vendored
View File

@ -7418,7 +7418,6 @@ for ac_header in \
mach/mach.h \
mach/machine.h \
machine/cpu.h \
machine/limits.h \
machine/sysarch.h \
mntent.h \
ncurses.h \
@ -7448,7 +7447,6 @@ for ac_header in \
sys/filio.h \
sys/ioctl.h \
sys/ipc.h \
sys/limits.h \
sys/link.h \
sys/mman.h \
sys/modem.h \
@ -17984,7 +17982,6 @@ for ac_func in \
sysinfo \
tcdrain \
thr_kill2 \
timegm \
usleep
do :

View File

@ -473,7 +473,6 @@ AC_CHECK_HEADERS(\
mach/mach.h \
mach/machine.h \
machine/cpu.h \
machine/limits.h \
machine/sysarch.h \
mntent.h \
ncurses.h \
@ -503,7 +502,6 @@ AC_CHECK_HEADERS(\
sys/filio.h \
sys/ioctl.h \
sys/ipc.h \
sys/limits.h \
sys/link.h \
sys/mman.h \
sys/modem.h \
@ -2217,7 +2215,6 @@ AC_CHECK_FUNCS(\
sysinfo \
tcdrain \
thr_kill2 \
timegm \
usleep
)
CFLAGS="$ac_save_CFLAGS"

View File

@ -407,6 +407,55 @@ BOOL WINAPI KERNEL32_FlushFileBuffers( HANDLE file )
}
/***********************************************************************
* DosDateTimeToFileTime (KERNEL32.@)
*/
BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, FILETIME *ft )
{
TIME_FIELDS fields;
LARGE_INTEGER time;
fields.Year = (fatdate >> 9) + 1980;
fields.Month = ((fatdate >> 5) & 0x0f);
fields.Day = (fatdate & 0x1f);
fields.Hour = (fattime >> 11);
fields.Minute = (fattime >> 5) & 0x3f;
fields.Second = (fattime & 0x1f) * 2;
fields.Milliseconds = 0;
if (!RtlTimeFieldsToTime( &fields, &time )) return FALSE;
ft->dwLowDateTime = time.u.LowPart;
ft->dwHighDateTime = time.u.HighPart;
return TRUE;
}
/***********************************************************************
* FileTimeToDosDateTime (KERNEL32.@)
*/
BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, WORD *fatdate, WORD *fattime )
{
TIME_FIELDS fields;
LARGE_INTEGER time;
if (!fatdate || !fattime)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
time.u.LowPart = ft->dwLowDateTime;
time.u.HighPart = ft->dwHighDateTime;
RtlTimeToTimeFields( &time, &fields );
if (fields.Year < 1980)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
*fattime = (fields.Hour << 11) + (fields.Minute << 5) + (fields.Second / 2);
*fatdate = ((fields.Year - 1980) << 9) + (fields.Month << 5) + fields.Day;
return TRUE;
}
/**************************************************************************
* Operations on file names *
**************************************************************************/

View File

@ -30,14 +30,6 @@
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_SYS_TIMES_H
# include <sys/times.h>
#endif
#ifdef HAVE_SYS_LIMITS_H
#include <sys/limits.h>
#elif defined(HAVE_MACHINE_LIMITS_H)
#include <machine/limits.h>
#endif
#include "ntstatus.h"
#define WIN32_NO_STATUS
@ -116,66 +108,6 @@ BOOL WINAPI GetDaylightFlag(void)
return GetTimeZoneInformation( &tzinfo) == TIME_ZONE_ID_DAYLIGHT;
}
/***********************************************************************
* DosDateTimeToFileTime (KERNEL32.@)
*/
BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft)
{
struct tm newtm;
#ifndef HAVE_TIMEGM
struct tm *gtm;
time_t time1, time2;
#endif
newtm.tm_sec = (fattime & 0x1f) * 2;
newtm.tm_min = (fattime >> 5) & 0x3f;
newtm.tm_hour = (fattime >> 11);
newtm.tm_mday = (fatdate & 0x1f);
newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
newtm.tm_year = (fatdate >> 9) + 80;
newtm.tm_isdst = -1;
#ifdef HAVE_TIMEGM
RtlSecondsSince1970ToTime( timegm(&newtm), (LARGE_INTEGER *)ft );
#else
time1 = mktime(&newtm);
gtm = gmtime(&time1);
time2 = mktime(gtm);
RtlSecondsSince1970ToTime( 2*time1-time2, (LARGE_INTEGER *)ft );
#endif
return TRUE;
}
/***********************************************************************
* FileTimeToDosDateTime (KERNEL32.@)
*/
BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
LPWORD fattime )
{
LARGE_INTEGER li;
ULONG t;
time_t unixtime;
struct tm* tm;
if (!fatdate || !fattime)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
li.u.LowPart = ft->dwLowDateTime;
li.u.HighPart = ft->dwHighDateTime;
if (!RtlTimeToSecondsSince1970( &li, &t ))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
unixtime = t;
tm = gmtime( &unixtime );
*fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
*fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday;
return TRUE;
}
/******************************************************************************
* GetTickCount64 (KERNEL32.@)
*/

View File

@ -539,9 +539,6 @@
/* Define to 1 if you have the <machine/cpu.h> header file. */
#undef HAVE_MACHINE_CPU_H
/* Define to 1 if you have the <machine/limits.h> header file. */
#undef HAVE_MACHINE_LIMITS_H
/* Define to 1 if you have the <machine/sysarch.h> header file. */
#undef HAVE_MACHINE_SYSARCH_H
@ -1021,9 +1018,6 @@
/* Define to 1 if you have the <sys/ipc.h> header file. */
#undef HAVE_SYS_IPC_H
/* Define to 1 if you have the <sys/limits.h> header file. */
#undef HAVE_SYS_LIMITS_H
/* Define to 1 if you have the <sys/link.h> header file. */
#undef HAVE_SYS_LINK_H
@ -1162,9 +1156,6 @@
/* Define to 1 if you have the <tiffio.h> header file. */
#undef HAVE_TIFFIO_H
/* Define to 1 if you have the `timegm' function. */
#undef HAVE_TIMEGM
/* Define to 1 if you have the `trunc' function. */
#undef HAVE_TRUNC