summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-01-02 07:18:56 +0000
committerJim Meyering <jim@meyering.net>2001-01-02 07:18:56 +0000
commit1efbe325bda465bab5f532359381a9e996eed93a (patch)
treea6afc09b51af19bb0d9c4da57907a394796d7868 /src
parent1f678f44f981654b3371561a3ec758a8c3907229 (diff)
downloadcoreutils-1efbe325bda465bab5f532359381a9e996eed93a.tar.xz
(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.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/ls.c b/src/ls.c
index fd85ef2f0..4b17742f1 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';