From: Miroslav Lichvar Date: Thu, 7 Aug 2014 12:23:33 +0000 (+0200) Subject: util: fix printing of timestamps when time_t is longer than long X-Git-Tag: 1.31-pre1~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc2892fbb079495e47ddd10d17e705cbfa6e1473;p=thirdparty%2Fchrony.git util: fix printing of timestamps when time_t is longer than long --- diff --git a/sysincl.h b/sysincl.h index 9bc5fe3c..2ecccb7f 100644 --- a/sysincl.h +++ b/sysincl.h @@ -62,10 +62,10 @@ #include #include -#if HAS_STDINT_H -#include -#elif defined(HAS_INTTYPES_H) +#ifdef HAS_INTTYPES_H #include +#elif HAS_STDINT_H +#include #else /* Tough */ #endif diff --git a/util.c b/util.c index e0039e8a..35bc12bd 100644 --- a/util.c +++ b/util.c @@ -210,9 +210,13 @@ UTI_TimevalToString(struct timeval *tv) char *result; result = NEXT_BUFFER; - /* TODO: time_t may be wider than long, switch to int64_t before 2038 */ +#ifdef HAVE_LONG_TIME_T + snprintf(result, BUFFER_LENGTH, "%"PRId64".%06lu", + (int64_t)tv->tv_sec, (unsigned long)tv->tv_usec); +#else snprintf(result, BUFFER_LENGTH, "%ld.%06lu", (long)tv->tv_sec, (unsigned long)tv->tv_usec); +#endif return result; }