diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-07-12 09:41:10 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-07-12 09:41:10 +0000 |
commit | 8dd4a2ef85264beba28733f364af90f544c08284 (patch) | |
tree | cc51d8b49e25d12cdcfa4c98431f848ed78896eb /bin | |
parent | d6608a05fc83d3e11b7f319b61cfe3d4181cf2e6 (diff) |
With the -l option, only call time() once per run instead of once per file
ok deraadt@
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ls/print.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/bin/ls/print.c b/bin/ls/print.c index 11aba934df3..b87cbddbaf8 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.27 2010/09/12 20:16:29 sobrado Exp $ */ +/* $OpenBSD: print.c,v 1.28 2012/07/12 09:41:09 guenther Exp $ */ /* $NetBSD: print.c,v 1.15 1996/12/11 03:25:39 thorpej Exp $ */ /* @@ -235,16 +235,22 @@ printtime(time_t ftime) { int i; char *longstring; + static time_t six_months_ago; + static int sma_set = 0; +#define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY) + if (! sma_set) { + six_months_ago = time(NULL) - SIXMONTHS; + sma_set = 1; + } longstring = ctime(&ftime); for (i = 4; i < 11; ++i) (void)putchar(longstring[i]); -#define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY) if (f_sectime) for (i = 11; i < 24; i++) (void)putchar(longstring[i]); - else if (ftime + SIXMONTHS > time(NULL)) + else if (ftime > six_months_ago) for (i = 11; i < 16; ++i) (void)putchar(longstring[i]); else { |