From adc816c05ac409c4a0e9cff03114cb7af2c5516d Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 5 Feb 2004 09:47:01 +0000 Subject: 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. --- src/stat.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3-70-g09d2