From: Joel Rosdahl Date: Sat, 14 Mar 2020 14:55:12 +0000 (+0100) Subject: win32: Log epoch timestamp if localtime_r fails X-Git-Tag: v4.0~568 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71edf04aa2c72b54c3b92f92532d41d5b1f5909c;p=thirdparty%2Fccache.git win32: Log epoch timestamp if localtime_r fails (cherry picked from commit 21fc81c11966d674c3b3cfe30ccf3cdff7f6dfee) --- 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),