]> 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>
Sat, 14 Mar 2020 14:55:12 +0000 (15:55 +0100)
src/util.c

index fe041ce3e5e81d5cdd8509781675a778853f1d0a..325a839504fcf0abefb6620839ea765cca3a7bfc 100644 (file)
@@ -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());
        }