Function _gmtime64 is available since msvcr70.dll. For older msvcrt versions
provide emulation via WinAPI FileTimeToSystemTime() function which is
available on all Windows versions and takes 64-bit time value. To retrieve
thread local storage for gmtime return value (struct tm), use the
_gmtime32() function with dummy value.
---
mingw-w64-crt/Makefile.am | 2 ++
mingw-w64-crt/lib-common/msvcrt.def.in | 2 +-
mingw-w64-crt/misc/_gmtime64.c | 46 ++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 1 deletion(-)
create mode 100644 mingw-w64-crt/misc/_gmtime64.c
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 266eed840eac..68dc2c50b294 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -576,6 +576,7 @@ src_msvcrt32=\
misc/_get_current_locale.c \
misc/_get_doserrno.c \
misc/_get_fmode.c \
+ misc/_gmtime64.c \
misc/_initterm_e.c \
misc/_set_doserrno.c \
misc/_set_fmode.c \
@@ -883,6 +884,7 @@ src_pre_msvcr70=\
misc/_aligned_offset_realloc.c \
misc/_aligned_realloc.c \
misc/_ftime64.c \
+ misc/_gmtime64.c \
misc/_time64.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 6cbe50c6f60c..487db673bcc3 100644
--- a/mingw-w64-crt/lib-common/msvcrt.def.in
+++ b/mingw-w64-crt/lib-common/msvcrt.def.in
@@ -1156,7 +1156,7 @@ _findnext64
F_NON_I386(_fstat64) ; i386 _fstat64 replaced by emu
F_NON_I386(_ftime64) ; i386 _ftime64 replaced by emu
_futime64
-_gmtime64
+F_NON_I386(_gmtime64) ; i386 _gmtime64 replaced by emu
_localtime64
_mktime64
F_X86_ANY(_osplatform DATA)
diff --git a/mingw-w64-crt/misc/_gmtime64.c b/mingw-w64-crt/misc/_gmtime64.c
new file mode 100644
index 000000000000..71723073a24b
--- /dev/null
+++ b/mingw-w64-crt/misc/_gmtime64.c
@@ -0,0 +1,46 @@
+/**
+ * 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>
+
+static const short int days_in_year[] = { -1, 30, 58, 89, 119, 150, 180, 211,
242, 272, 303, 333, 364 };
+
+static struct tm *__cdecl emu__gmtime64(const __time64_t *timeptr)
+{
+ struct tm *tmptr;
+ unsigned long long value;
+ FILETIME filetime;
+ SYSTEMTIME systemtime;
+
+ value = (*timeptr * 10000000) + 116444736000000000LL;
+ filetime.dwLowDateTime = value & 0xffffffff;
+ filetime.dwHighDateTime = value >> 32;
+ if (!FileTimeToSystemTime(&filetime, &systemtime))
+ return NULL;
+
+ /* retrieve thread local storage for gmtime tm */
+ tmptr = _gmtime32(&(__time32_t){0});
+ if (!tmptr)
+ return NULL;
+
+ tmptr->tm_sec = systemtime.wSecond;
+ tmptr->tm_min = systemtime.wMinute;
+ tmptr->tm_hour = systemtime.wHour;
+ tmptr->tm_mday = systemtime.wDay;
+ tmptr->tm_mon = systemtime.wMonth-1;
+ tmptr->tm_year = systemtime.wYear-1900;
+ tmptr->tm_wday = systemtime.wDayOfWeek;
+ tmptr->tm_yday = days_in_year[tmptr->tm_mon] + systemtime.wDay +
((systemtime.wMonth >= 3 && ((systemtime.wYear % 4 == 0 && systemtime.wYear %
100 != 0) || systemtime.wYear % 400 == 0)) ? 1 : 0);
+ tmptr->tm_isdst = 0;
+ return tmptr;
+}
+
+#define RETT struct tm *
+#define FUNC _gmtime64
+#define ARGS const __time64_t *timeptr
+#define CALL timeptr
+#include "msvcrt_or_emu_glue.h"
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public