]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Include "inttostr.h".
authorJim Meyering <jim@meyering.net>
Thu, 5 Feb 2004 09:47:01 +0000 (09:47 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 5 Feb 2004 09:47:01 +0000 (09:47 +0000)
(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

index bc3cfb8cb5460b4bd5f79a7ed2560536d016f594..15ebded3ea945c4bdc4eb83d1ca907a152fe1585 100644 (file)
@@ -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;
 }