crt: Provide emulation of _time64 function

Function _time64 is available since msvcr70.dll. For older msvcrt versions
provide emulation via WinAPI GetSystemTime() function which is available on
all Windows versions and returns native value in SYSTEMTIME format.

Signed-off-by: Martin Storsjö <martin@martin.st>
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 1c40fe3..05e3300 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -540,6 +540,7 @@
   misc/_free_locale.c \
   misc/_get_current_locale.c \
   misc/_initterm_e.c \
+  misc/_time64.c \
   misc/btowc.c \
   misc/imaxabs.c \
   misc/lc_locale_func.c \
@@ -828,6 +829,7 @@
   misc/_aligned_offset_malloc.c \
   misc/_aligned_offset_realloc.c \
   misc/_aligned_realloc.c \
+  misc/_time64.c \
   misc/lc_locale_func.c \
   misc/strtoimax.c \
   misc/strtoumax.c \
diff --git a/mingw-w64-crt/lib-common/msvcrt.def.in b/mingw-w64-crt/lib-common/msvcrt.def.in
index 2df0c02..82694e4 100644
--- a/mingw-w64-crt/lib-common/msvcrt.def.in
+++ b/mingw-w64-crt/lib-common/msvcrt.def.in
@@ -1161,7 +1161,7 @@
 _mktime64
 F_X86_ANY(_osplatform DATA)
 F_NON_I386(_stat64) ; i386 _stat64 replaced by emu
-_time64
+F_NON_I386(_time64) ; i386 _time64 replaced by emu
 _utime64
 _wctime64
 _wfindfirst64
diff --git a/mingw-w64-crt/misc/_time64.c b/mingw-w64-crt/misc/_time64.c
new file mode 100644
index 0000000..0eb9a99
--- /dev/null
+++ b/mingw-w64-crt/misc/_time64.c
@@ -0,0 +1,31 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <windows.h>
+#include <time.h>
+
+#include "filetime_to_time64.h"
+
+static __time64_t __cdecl emu__time64(__time64_t *timeptr)
+{
+    SYSTEMTIME systemtime;
+    FILETIME filetime;
+    __time64_t time64;
+    GetSystemTime(&systemtime);
+    if (SystemTimeToFileTime(&systemtime, &filetime))
+        time64 = filetime_to_time64(&filetime);
+    else
+        time64 = -1;
+    if (timeptr)
+        *timeptr = time64;
+    return time64;
+}
+
+#define RETT __time64_t
+#define FUNC _time64
+#define ARGS __time64_t *timeptr
+#define CALL timeptr
+#include "msvcrt_or_emu_glue.h"