diff options
author | Jim Meyering <jim@meyering.net> | 2004-02-05 09:47:01 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-02-05 09:47:01 +0000 |
commit | adc816c05ac409c4a0e9cff03114cb7af2c5516d (patch) | |
tree | 484edb77e8ee4044c012035b1fe6dddbacd3de2b /src | |
parent | b5cfd989df45e22aa16c390c650fa1396d7eec3f (diff) | |
download | coreutils-adc816c05ac409c4a0e9cff03114cb7af2c5516d.tar.xz |
Include "inttostr.h".
(human_time): Print the date/time as a number of seconds since the
epoch if it can't be converted by localtime. This is better than
just saying "invalid", and is consistent with what "ls" does.
Don't dump core if the year has more than 48 digits; this isn't
possible on any contemporary host, but we might as well do it right.
Diffstat (limited to 'src')
-rw-r--r-- | src/stat.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/stat.c b/src/stat.c index bc3cfb8cb..15ebded3e 100644 --- a/src/stat.c +++ b/src/stat.c @@ -49,6 +49,7 @@ #include "file-type.h" #include "fs.h" #include "getopt.h" +#include "inttostr.h" #include "quote.h" #include "quotearg.h" #include "strftime.h" @@ -328,13 +329,15 @@ human_access (struct stat const *statbuf) static char * human_time (time_t t, int t_ns) { - static char str[80]; - struct tm *tm = localtime (&t); + static char str[MAX (INT_BUFSIZE_BOUND (intmax_t), + (INT_STRLEN_BOUND (int) /* YYYY */ + + 1 /* because YYYY might equal INT_MAX + 1900 */ + + sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +ZZZZ"))]; + struct tm const *tm = localtime (t); if (tm == NULL) - { - G_fail = 1; - return (char *) _("*** invalid date/time ***"); - } + return (TYPE_SIGNED (time_t) + ? imaxtostr (t, str) + : umaxtostr (t, str)); nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, t_ns); return str; } |