From 21fc81c11966d674c3b3cfe30ccf3cdff7f6dfee Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 14 Mar 2020 15:55:12 +0100 Subject: [PATCH] win32: Log epoch timestamp if localtime_r fails --- src/util.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/util.c b/src/util.c index fe041ce3e..325a83950 100644 --- a/src/util.c +++ b/src/util.c @@ -97,12 +97,11 @@ log_prefix(bool log_updated_time) struct tm tm; struct timeval tv; gettimeofday(&tv, NULL); -#ifdef __MINGW64_VERSION_MAJOR - localtime_r((time_t *)&tv.tv_sec, &tm); -#else - localtime_r(&tv.tv_sec, &tm); -#endif - strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", &tm); + if (localtime_r((time_t *)&tv.tv_sec, &tm) != NULL) { + strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", &tm); + } else { + snprintf(timestamp, sizeof(timestamp), "%lu", tv.tv_sec); + } snprintf(prefix, sizeof(prefix), "[%s.%06d %-5d] ", timestamp, (int)tv.tv_usec, (int)getpid()); } -- 2.47.2