]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
win32: Log epoch timestamp if localtime_r fails
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 14 Mar 2020 14:55:12 +0000 (15:55 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 18 Mar 2020 19:44:05 +0000 (20:44 +0100)
(cherry picked from commit 21fc81c11966d674c3b3cfe30ccf3cdff7f6dfee)

src/logging.cpp

index e1c7fcdd46a8447e9166cdab7c1c42cf18521fdf..bac365637759766bffb17c730ab2640d2b4ab0da 100644 (file)
@@ -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),