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: v3.7.8~1 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=21fc81c11966d674c3b3cfe30ccf3cdff7f6dfee;p=thirdparty%2Fccache.git win32: Log epoch timestamp if localtime_r fails --- diff --git a/src/util.c b/src/util.c index fe041ce3e..325a83950 100644 --- a/src/util.c +++ b/src/util.c @@ -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()); }