On 11/04/2010 11:34 PM, Jim Meyering wrote:
> Pádraig Brady wrote:
>> I still slightly prefer just using %.X as
>> it's backwards compat with older coreutils (excluding 8.6).
>
> So do I.
I built that and tried it out, and found another problem that has been
annoying me for years in other programs: 'stat' prints out unnecessary
trailing zeros for time stamps, when the file system resolution is
coarser than nanosecond resolution. So I figured I'd fix that too,
for 'stat' (other programs can be fixed later). With this fix, %.X
outputs the time stamp but omits trailing zeros if it can infer that
the file system would always put zeros there. If you want a specific
number of zeros, you can use something like %.3X or %.9X (or %.100X :-).
>From d37bad3d644a98887402b5398b7280701a7b7559 Mon Sep 17 00:00:00 2001
From: Paul Eggert
Date: Fri, 5 Nov 2010 19:35:12 -0700
Subject: [PATCH] stat: use e.g. %.3X instead of %X.%3:X for sub-second precision
* NEWS: Document this.
* doc/coreutils.texi (stat invocation): Likewise.
* gl/lib/fstimeprec.c, gl/lib/fstimeprec.h, gl/modules/fstimeprec:
* gl/modules/fstimeprec-tests, gl/tests/test-fstimeprec.c:
New files.
* bootstrap.conf (gnulib_modules): Add fstimeprec.
* src/stat.c: Include fstimeprec.h. Don't include xstrtol.h.
(decimal_point, decimal_point_len): New static vars.
(main): Initialize them.
(epoch_sec, out_ns): Remove.
(out_int, out_uint): Now returns whatever printf returned.
(out_minus_zero, out_epoch_secs): New functions.
(print_stat): Use out_epoch_sec instead of out_ns and epoch_sec.
(print_stat, print_it, usage): Remove the %:X-style formats.
* tests/misc/stat-nanoseconds: Set TZ=UTC0 to avoid problems
with weird time zones. Use a time stamp near the Epoch so that we
don't have to worry about leap seconds. Redo test cases to match
new behavior.
* tests/touch/60-seconds: Change %Y.%:Y to %.9Y, to adjust to
new behavior.
---
NEWS| 10 +--
bootstrap.conf |1 +
doc/coreutils.texi | 37
gl/lib/fstimeprec.c | 178 +++
gl/lib/fstimeprec.h | 22 +
gl/modules/fstimeprec | 24 +
gl/modules/fstimeprec-tests | 10 ++
gl/tests/test-fstimeprec.c | 74 +++
src/stat.c | 218 ++-
tests/misc/stat-nanoseconds | 25 +++--
tests/touch/60-seconds |2 +-
11 files changed, 480 insertions(+), 121 deletions(-)
create mode 100644 gl/lib/fstimeprec.c
create mode 100644 gl/lib/fstimeprec.h
create mode 100644 gl/modules/fstimeprec
create mode 100644 gl/modules/fstimeprec-tests
create mode 100644 gl/tests/test-fstimeprec.c
diff --git a/NEWS b/NEWS
index 3b9bea2..1e5a8db 100644
--- a/NEWS
+++ b/NEWS
@@ -20,16 +20,12 @@ GNU coreutils NEWS-*-
outline -*-
stat's %X, %Y, and %Z directives once again print only the integer
part of seconds since the epoch. This reverts a change from
coreutils-8.6, that was deemed unnecessarily disruptive. To obtain
- the nanoseconds portion corresponding to %X, you may now use %:X.
- I.e., to print the floating point number of seconds using maximum
- precision, use this format string: %X.%:X. Likewise for %Y, %Z and %W.
+ a full resolution time stamp for %X, use %.X; if you want (say) just
+ 3 fractional digits, use %.3X. Likewise for %Y and %Z.
stat's new %W format directive would print floating point seconds.
However, with the above change to %X, %Y and %Z, we've made %W work
- the same way: %W now expands to seconds since the epoch (or 0 when
- not supported), and %:W expands to the nanoseconds portion, or to
- 0 if not supported.
-
+ the same way as the others.
* Noteworthy changes in release 8.6 (2010-10-15) [stable]
diff --git a/bootstrap.conf b/bootstrap.conf
index 18ef914..5a6ebae 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -85,6 +85,7 @@ gnulib_modules="
freopen
freopen-safer
fseeko
+ fstimeprec
fsusage
fsync
ftello
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index be5999f..8dfb069 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -10707,37 +10707,36 @@ The valid @var{format} directives for files with
@option{--format} and
@item %U - User name of owner
@item %w - Time of file birth, or @samp{-} if unknown
@item %W - Time of file birth as seconds since Epoch, or @samp{0}
-...@item %:W - Time of file birth: nanoseconds remainder, or @samp{0}
@item %x - Time of last access
@item %X - Time of last access as seconds since Epoch
-...@item %:X - Time of last access: nanoseconds remainder
@item %y - Time of last modification
@item %Y - Time of last modification as seconds since Epoch
-...@item %:Y - Time of last modification: nanoseconds remainder
@item %z - Time of last change
@item %Z - Time of last change as seconds since Epoch
-...@item %:Z - Time of last change: nanoseconds remainder
@end itemize
-Note