bug-coreutils
[Top][All Lists]
Advanced

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

Re: truncate.c fails to compile on make distcheck


From: Pádraig Brady
Subject: Re: truncate.c fails to compile on make distcheck
Date: Thu, 26 Jun 2008 11:14:48 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Jim Meyering wrote:
> By the way, does %zu work reliably everywhere now?
> In the past, we've converted such values to strings via umaxtostr,
> to accommodate older systems.
> 
> For ssize and nsize, I have a slight preference for the
> cast-free approach of using %s with imaxtostr.

Yes I suppose %z and PRIdMAX are C99 specific.
How about the attached patch?

cheers,
Pádraig.
>From f06afe7a149c3d0340eeddd67718b3f7254a8251 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden>
Date: Thu, 26 Jun 2008 11:10:13 +0100
Subject: [PATCH] truncate: Fix portability issues with printing numbers in 
error messages

* src/truncate.c: Remove C99 specific format specifiers,
and explicitly convert from off_t to intmax_t which
may be a different type.
---
 src/truncate.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/truncate.c b/src/truncate.c
index 2435a12..f5bcfdc 100644
--- a/src/truncate.c
+++ b/src/truncate.c
@@ -32,6 +32,7 @@
 
 #include "system.h"
 #include "error.h"
+#include "inttostr.h"
 #include "posixver.h"
 #include "quote.h"
 #include "xstrtol.h"
@@ -158,9 +159,11 @@ do_ftruncate (int fd, char const *fname, off_t ssize, 
rel_mode_t rel_mode)
       size_t const blksize = ST_BLKSIZE (sb);
       if (ssize < OFF_T_MIN / blksize || ssize > OFF_T_MAX / blksize)
         {
+          char jbuf[INT_BUFSIZE_BOUND (intmax_t)];
+          char zbuf[INT_BUFSIZE_BOUND (uintmax_t)];
           error (0, 0,
-                 _("overflow in %" PRIdMAX
-                   " * %zu byte blocks for file %s"), ssize, blksize,
+                 _("overflow in %s * %s byte blocks for file %s"),
+                 imaxtostr (ssize, jbuf), umaxtostr (blksize, zbuf),
                  quote (fname));
           return 1;
         }
@@ -239,9 +242,10 @@ do_ftruncate (int fd, char const *fname, off_t ssize, 
rel_mode_t rel_mode)
       else if (S_ISREG (sb.st_mode) || S_ISDIR (sb.st_mode)
                || S_TYPEISSHM (&sb))
         {
+          char jbuf[INT_BUFSIZE_BOUND (intmax_t)];
           error (0, ftruncate_errno,
-                 _("truncating %s at %" PRIdMAX " bytes"), quote (fname),
-                 nsize);
+                 _("truncating %s at %s bytes"), quote (fname),
+                 imaxtostr (nsize, jbuf));
           return 1;
         }
       return 0;
-- 
1.5.3.6


reply via email to

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