From 0bc672a9be9caf0482bf1f2b1e528b6b20b8eaaf Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 19 Jul 2020 10:39:43 +0100 Subject: ts: correct output in 64-bit build ts failed to output the correct time when built for 64-bit Windows. In 64-bit builds time_t is a 64-bit quantity whereas the tv_sec member of struct timeval is 32-bit. https://sourceforge.net/p/mingw-w64/bugs/783/ Use a temporary time_t value in 64-bit builds. --- miscutils/ts.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/miscutils/ts.c b/miscutils/ts.c index f2d367654..f769d663b 100644 --- a/miscutils/ts.c +++ b/miscutils/ts.c @@ -22,6 +22,9 @@ int ts_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ts_main(int argc UNUSED_PARAM, char **argv) { struct timeval base; +#if ENABLE_PLATFORM_MINGW32 && !defined(_USE_32BIT_TIME_T) + time_t t; +#endif unsigned opt; char *frac; char *fmt_dt2str; @@ -70,7 +73,12 @@ int ts_main(int argc UNUSED_PARAM, char **argv) if (opt & 1) /* -i */ base = ts1; } +#if ENABLE_PLATFORM_MINGW32 && !defined(_USE_32BIT_TIME_T) + t = ts.tv_sec; + localtime_r(&t, &tm_time); +#else localtime_r(&ts.tv_sec, &tm_time); +#endif strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time); if (!frac) { printf("%s %s", date_buf, line); -- cgit v1.2.3-55-g6feb