[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: coreutils-5.1.2 and the stat command
From: |
Jim Meyering |
Subject: |
Re: coreutils-5.1.2 and the stat command |
Date: |
Mon, 02 Feb 2004 09:11:29 +0100 |
"Nelson H. F. Beebe" <address@hidden> wrote:
...
> with this output on SGI IRIX 6.5:
>
> % ls -l --full-time /bin/true
> -rwxr-xr-x 1 root sys 312 1999-11-04 12:07:38.887783200 -0700 /bin/true
> % stat /bin/true
...
> Change: 1999-11-04 12:07:38.000000000 -0700
...
> 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.
Right you are.
Thanks for reporting that.
Here's the fix:
Print actual fractional seconds in time stamps, not just `.00000000'.
* src/stat.c (human_time): Add and use new parameter, t_ns.
(print_stat): Update callers.
* src/ls.c (TIMESPEC_NS): Remove definition.
* src/system.h (TIMESPEC_NS): Define here, instead, now that stat.c
also uses this macro.
Nelson H. F. Beebe noticed that ls --full-time printed nonzero
fractional seconds for files on an XFS file system, but that stat's
fractional seconds were always zero.
Index: stat.c
===================================================================
RCS file: /fetish/cu/src/stat.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -p -u -r1.61 -r1.62
--- stat.c 21 Jan 2004 23:45:21 -0000 1.61
+++ stat.c 2 Feb 2004 07:59:58 -0000 1.62
@@ -326,7 +326,7 @@ human_access (struct stat const *statbuf
}
static char *
-human_time (time_t const *t)
+human_time (time_t const *t, int t_ns)
{
static char str[80];
struct tm *tm = localtime (t);
@@ -335,7 +335,7 @@ human_time (time_t const *t)
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, t_ns);
return str;
}
@@ -525,7 +525,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 +534,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 +543,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");
Index: system.h
===================================================================
RCS file: /fetish/cu/src/system.h,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -p -u -r1.79 -r1.80
--- system.h 22 Jan 2004 21:02:22 -0000 1.79
+++ system.h 2 Feb 2004 07:59:35 -0000 1.80
@@ -548,6 +548,12 @@ initialize_exit_failure (int status)
#define CTIME_CMP(a, b) ST_TIME_CMP (a, b, st_ctime, st_ctim.ST_MTIM_NSEC)
#define MTIME_CMP(a, b) ST_TIME_CMP (a, b, st_mtime, st_mtim.ST_MTIM_NSEC)
+#ifdef ST_MTIM_NSEC
+# define TIMESPEC_NS(timespec) ((timespec).ST_MTIM_NSEC)
+#else
+# define TIMESPEC_NS(timespec) 0
+#endif
+
#ifndef RETSIGTYPE
# define RETSIGTYPE void
#endif
Index: ls.c
===================================================================
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.351
retrieving revision 1.352
diff -u -p -u -r1.351 -r1.352
--- ls.c 21 Jan 2004 23:20:16 -0000 1.351
+++ ls.c 2 Feb 2004 07:59:23 -0000 1.352
@@ -143,12 +143,6 @@ int rpl_lstat (const char *, struct stat
# define DT_INIT(Val) /* empty */
#endif
-#ifdef ST_MTIM_NSEC
-# define TIMESPEC_NS(timespec) ((timespec).ST_MTIM_NSEC)
-#else
-# define TIMESPEC_NS(timespec) 0
-#endif
-
#if ! HAVE_STRUCT_STAT_ST_AUTHOR
# define st_author st_uid
#endif
- Re: coreutils-5.1.2 and the stat command,
Jim Meyering <=