From 71edf04aa2c72b54c3b92f92532d41d5b1f5909c 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 (cherry picked from commit 21fc81c11966d674c3b3cfe30ccf3cdff7f6dfee) --- src/logging.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/logging.cpp b/src/logging.cpp index e1c7fcdd4..bac365637 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -112,11 +112,11 @@ log_prefix(bool log_updated_time) struct tm tm; struct timeval tv; gettimeofday(&tv, nullptr); -# ifdef __MINGW64_VERSION_MAJOR - localtime_r((time_t*)&tv.tv_sec, &tm); -# else - localtime_r(&tv.tv_sec, &tm); -# endif + 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); + } strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", &tm); snprintf(prefix, sizeof(prefix), -- 2.47.3