GNU bug report logs - #7325
new test failure due to non-portability of printf formats like %05.3s

Previous Next

Package: coreutils;

Reported by: Jim Meyering <jim <at> meyering.net>

Date: Wed, 3 Nov 2010 18:56:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #53 received at 7325 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: Eric Blake <eblake <at> redhat.com>, 7325 <at> debbugs.gnu.org,
	Pádraig Brady <P <at> draigBrady.com>
Subject: Re: bug#7325: new test failure due to non-portability of printf
	formats like %05.3s
Date: Sat, 06 Nov 2010 09:20:06 +0100
Paul Eggert wrote:

> 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 :-).

Nice!

> 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

Both of those ideas seem useful enough to employ
in general, so I copied your log comments into the code.

> new behavior.
> * tests/touch/60-seconds: Change %Y.%:Y to %.9Y, to adjust to
> new behavior.

I haven't looked through all of it yet, but here's
a small change I'll fold in:

diff --git a/tests/misc/stat-nanoseconds b/tests/misc/stat-nanoseconds
index 9071ae9..0f41eb0 100755
--- a/tests/misc/stat-nanoseconds
+++ b/tests/misc/stat-nanoseconds
@@ -19,9 +19,11 @@
 test "$VERBOSE" = yes && stat --version
 . "${srcdir=.}/init.sh"; path_prepend_ ../src

+# Set this to avoid problems with weird time zones.
 TZ=UTC0
 export TZ

+# Use a time stamp near the Epoch to avoid trouble with leap seconds.
 touch -d '1970-01-01 18:43:33.023456789' k || framework_failure_

 ls --full-time | grep 18:43:33.023456789 \


FYI, after I push this, I'll update to the latest from gnulib
for strtod and icc-related fixes and make another snapshot.




This bug report was last modified 14 years and 191 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.