From: Jim Meyering Date: Tue, 2 Jan 2001 07:18:56 +0000 (+0000) Subject: (print_long_format): X-Git-Tag: FILEUTILS-4_0_36~111 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1efbe325bda465bab5f532359381a9e996eed93a;p=thirdparty%2Fcoreutils.git (print_long_format): Report the year for files even slightly in the future. Avoid overflow problems near Y2038 on 32-bit hosts. To calculate "six months", take half the average Gregorian year, not 180 days. --- diff --git a/src/ls.c b/src/ls.c index fd85ef2f01..4b17742f19 100644 --- a/src/ls.c +++ b/src/ls.c @@ -2445,13 +2445,19 @@ print_long_format (const struct fileinfo *f) if ((when_local = localtime (&when))) { - /* The file is recent if it is neither old nor in the future. - POSIX says the cutoff is 6 months old; - approximate this by 6*30 days. - Allow a 1 hour slop factor for what is considered "the future", - to allow for NFS server/client clock disagreement. */ - int recent = (current_time <= when + 6L * 30L * 24L * 60L * 60L - && when - 60L * 60L <= current_time); + /* If the file appears to be in the future, update the current + time, in case the file happens to have been modified since + the last time we checked the clock. */ + time_t now = (current_time < when + ? (current_time = time (NULL)) + : current_time); + + /* Consider a time to be recent if it is within the past six + months. A Gregorian year has 365.2425 * 24 * 60 * 60 == + 31556952 seconds on the average. Write this value as an + integer constant to avoid floating point hassles. */ + time_t six_months_ago = now - 31556952 / 2; + int recent = six_months_ago <= when && when <= now; char const *fmt = long_time_format[recent]; *p = '\1';