]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
util: fix printing of timestamps when time_t is longer than long
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 7 Aug 2014 12:23:33 +0000 (14:23 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 15 Aug 2014 08:58:44 +0000 (10:58 +0200)
sysincl.h
util.c

index 9bc5fe3c1af206e1da165f54619dd5b42f984d7a..2ecccb7f09bc34e6c3199d677c2830feeaae220b 100644 (file)
--- a/sysincl.h
+++ b/sysincl.h
 #include <syslog.h>
 #include <time.h>
 
-#if HAS_STDINT_H
-#include <stdint.h>
-#elif defined(HAS_INTTYPES_H)
+#ifdef HAS_INTTYPES_H
 #include <inttypes.h>
+#elif HAS_STDINT_H
+#include <stdint.h>
 #else
 /* Tough */
 #endif
diff --git a/util.c b/util.c
index e0039e8a282e1cb5f29fd7e9970affa5639e4751..35bc12bdddf2daa99f1cd3db142489d9df95e0db 100644 (file)
--- 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;
 }