bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: coreutils-5.1.2 and the stat command


From: Paul Eggert
Subject: Re: coreutils-5.1.2 and the stat command
Date: 31 Jan 2004 23:37:54 -0800
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

"Nelson H. F. Beebe" <address@hidden> writes:

> I suspect that the omission of the nanoseconds values in the
> timestamps reported by GNU stat is simply an oversight that can be
> easily rectified, and should be.

Thanks for reporting that.  The following patch works for me on Solaris 8.

2004-01-31  Paul Eggert  <address@hidden>

        * src/stat.c: Include timespec.h.
        (human_time): Accept nanoseconds arg.  Also, accept time
        rather than pointer-to-const-time, for clarity.  All callers changed.
        (print_stat): Pass nanoseconds arg to human_time.
        Problem reported by Nelson H. F. Beebe.

Index: stat.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/stat.c,v
retrieving revision 1.61
diff -p -u -r1.61 stat.c
--- stat.c      21 Jan 2004 23:45:21 -0000      1.61
+++ stat.c      1 Feb 2004 07:21:28 -0000
@@ -52,6 +52,7 @@
 #include "quote.h"
 #include "quotearg.h"
 #include "strftime.h"
+#include "timespec.h"
 #include "xreadlink.h"
 
 #define NAMEMAX_FORMAT PRIuMAX
@@ -326,16 +327,16 @@ human_access (struct stat const *statbuf
 }
 
 static char *
-human_time (time_t const *t)
+human_time (time_t t, int ns)
 {
   static char str[80];
-  struct tm *tm = localtime (t);
+  struct tm *tm = localtime (&t);
   if (tm == NULL)
     {
       G_fail = 1;
       return (char *) _("*** invalid date/time ***");
     }
-  nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, 0);
+  nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, ns);
   return str;
 }
 
@@ -525,7 +526,8 @@ print_stat (char *pformat, char m, char 
       break;
     case 'x':
       strcat (pformat, "s");
-      printf (pformat, human_time (&(statbuf->st_atime)));
+      printf (pformat, human_time (statbuf->st_atime,
+                                  TIMESPEC_NS (statbuf->st_atim)));
       break;
     case 'X':
       strcat (pformat, "d");
@@ -533,7 +535,8 @@ print_stat (char *pformat, char m, char 
       break;
     case 'y':
       strcat (pformat, "s");
-      printf (pformat, human_time (&(statbuf->st_mtime)));
+      printf (pformat, human_time (statbuf->st_mtime,
+                                  TIMESPEC_NS (statbuf->st_mtim)));
       break;
     case 'Y':
       strcat (pformat, "d");
@@ -541,7 +544,8 @@ print_stat (char *pformat, char m, char 
       break;
     case 'z':
       strcat (pformat, "s");
-      printf (pformat, human_time (&(statbuf->st_ctime)));
+      printf (pformat, human_time (statbuf->st_ctime,
+                                  TIMESPEC_NS (statbuf->st_ctim)));
       break;
     case 'Z':
       strcat (pformat, "d");




reply via email to

[Prev in Thread] Current Thread [Next in Thread]