From 290701e02dc3dbc2dc6e4ce5dce2a318d322459c Mon Sep 17 00:00:00 2001 From: "Gary E. Miller" Date: Wed, 10 Aug 2016 12:40:43 -0700 Subject: Fix timespec_str() to the year 2286 on 32 bit systems. --- timespec_str.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/timespec_str.c b/timespec_str.c index 755adb9a..e297d14b 100644 --- a/timespec_str.c +++ b/timespec_str.c @@ -32,10 +32,14 @@ * * So 12 chars, like this: "-0.123456789" * - * Absolute worst case is 10 digits of seconds. + * Probable worst case is 10 digits of seconds, + * but standards do not provide hard limits to time_t * So 21 characters like this: "-2147483647.123456789" * -*/ + * date --date='@2147483647' is: Mon Jan 18 19:14:07 PST 2038 + * date --date='@9999999999' is: Sat Nov 20 09:46:39 PST 2286 + * + */ void timespec_str(const struct timespec *ts, char *buf, size_t buf_size) { char sign = ' '; @@ -43,9 +47,9 @@ void timespec_str(const struct timespec *ts, char *buf, size_t buf_size) if ( (0 > ts->tv_nsec ) || ( 0 > ts->tv_sec ) ) { sign = '-'; } - (void) snprintf( buf, buf_size, "%c%ld.%09ld", + (void) snprintf( buf, buf_size, "%c%lld.%09ld", sign, - (long)labs(ts->tv_sec), + (long long)llabs(ts->tv_sec), (long)labs(ts->tv_nsec)); } -- cgit v1.2.1