Alexandre Julliard : kernel32: Reimplement DosDateTimeToFileTime/FileTimeToDosDateTime using ntdll functions.

Alexandre Julliard julliard at winehq.org
Tue May 26 17:17:06 CDT 2020


Module: wine
Branch: master
Commit: b6a38ea676081664a1fe0b318fe56339b255b6ed
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=b6a38ea676081664a1fe0b318fe56339b255b6ed

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue May 26 14:05:10 2020 +0200

kernel32: Reimplement DosDateTimeToFileTime/FileTimeToDosDateTime using ntdll functions.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 configure            |  3 ---
 configure.ac         |  3 ---
 dlls/kernel32/file.c | 49 +++++++++++++++++++++++++++++++++++++
 dlls/kernel32/time.c | 68 ----------------------------------------------------
 include/config.h.in  |  9 -------
 5 files changed, 49 insertions(+), 83 deletions(-)

diff --git a/configure b/configure
index a5516fe60e..b652ddbf79 100755
--- a/configure
+++ b/configure
@@ -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 :
diff --git a/configure.ac b/configure.ac
index b43ec73929..c0f60fe694 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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"
diff --git a/dlls/kernel32/file.c b/dlls/kernel32/file.c
index 4f25331a89..29dd5791af 100644
--- a/dlls/kernel32/file.c
+++ b/dlls/kernel32/file.c
@@ -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                          *
  **************************************************************************/
diff --git a/dlls/kernel32/time.c b/dlls/kernel32/time.c
index 4b959684c6..94ccbfb2b9 100644
--- a/dlls/kernel32/time.c
+++ b/dlls/kernel32/time.c
@@ -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.@)
  */
diff --git a/include/config.h.in b/include/config.h.in
index 2642487312..720cbd4a5d 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -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
 




More information about the wine-cvs mailing list