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 #32 received at 7325 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Jim Meyering <jim <at> meyering.net>
Cc: 7325 <at> debbugs.gnu.org, Eric Blake <eblake <at> redhat.com>
Subject: Re: bug#7325: new test failure due to non-portability of printf
	formats like %05.3s
Date: Thu, 04 Nov 2010 13:10:04 -0700
On 11/04/10 00:56, Jim Meyering wrote:

> However, what about Eric's example?
> 
>   $ src/stat-p -c '_%-0 010.4:X_' k  # yours
>   _234       _
>   $ src/stat-j -c '_%-0 010.4:X_' k  # mine
>   _0234      _

That's simply an issue of whether the value is considered to be signed
or unsigned, and can be fixed by the patch at the end of this message.

However, let me take a step back a minute.  Do users really want all
this functionality?  Personally, what I'd like to see is a single
format like this:

   %.3X

that prints out the entire seconds since the Epoch, truncated
to millseconds.  That's simpler than what we require now:

   %X.%.3:X

The changelogs suggest that we used to do things the simpler way,
but changed on Oct. 21.  I don't recall this being discussed: I 
assume it was due to floating point rounding issues.  Still, I'd
prefer the simpler notation, and we should be able to implement it
without floating point.  Would that be OK?  The idea would be
to support ".PRECISION" in the formats for W, X, Y, and Z, and
to drop support for ':W' and the like.

From 1dc473cc61099d5a1bf6bc26358bafd81cd670bd Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert <at> cs.ucla.edu>
Date: Thu, 4 Nov 2010 12:56:17 -0700
Subject: [PATCH] * src/stat.c (out_ns): Treat the ns value as being signed.

---
 src/stat.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/stat.c b/src/stat.c
index c1def13..dd352a4 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -481,7 +481,7 @@ out_ns (char *pformat, size_t prefix_len, struct timespec arg)
      in the modifier, then then treat the modifier as operating
      on the default representation, i.e., a zero padded number
      of width 9.  */
-  unsigned long int ns = arg.tv_nsec;
+  long int ns = arg.tv_nsec;
   char *dot = memchr (pformat, '.', prefix_len);
 
   if (dot)
@@ -504,12 +504,12 @@ out_ns (char *pformat, size_t prefix_len, struct timespec arg)
         return;
       for (; precision < 9; precision++)
         ns /= 10;
-      strcpy (dot, "lu");
+      strcpy (dot, "ld");
     }
   else
     {
-      char const *fmt = (prefix_len == 1) ? "09lu" : "lu";
-      /* Note that pformat is big enough, as %:X -> %09lu
+      char const *fmt = (prefix_len == 1) ? "09ld" : "ld";
+      /* Note that pformat is big enough, as %:X -> %09ld
          and two extra bytes are already allocated.  */
       strcpy (pformat + prefix_len, fmt);
     }
-- 
1.7.2





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

Previous Next


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