aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2020-03-14 15:55:12 +0100
committerJoel Rosdahl <joel@rosdahl.net>2020-03-18 20:44:05 +0100
commit71edf04aa2c72b54c3b92f92532d41d5b1f5909c (patch)
tree569ebff19e568870dfca02a3a1104ed2da34058b
parent6080b1e8a6fce1216e8c9c943c76c78d1f87681e (diff)
downloadccache-71edf04aa2c72b54c3b92f92532d41d5b1f5909c.tar.gz
ccache-71edf04aa2c72b54c3b92f92532d41d5b1f5909c.tar.bz2
ccache-71edf04aa2c72b54c3b92f92532d41d5b1f5909c.zip
win32: Log epoch timestamp if localtime_r fails
(cherry picked from commit 21fc81c11966d674c3b3cfe30ccf3cdff7f6dfee)
-rw-r--r--src/logging.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/logging.cpp b/src/logging.cpp
index e1c7fcdd..bac36563 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),