]> git.cworth.org Git - gzip/blobdiff - util.c
Imported Debian patch 1.3.5-10
[gzip] / util.c
diff --git a/util.c b/util.c
index 3adfb264e958d177eaa818204e13fe12c419cac4..65851631152aee7b285fd87a2496b6b201c3dd9e 100644 (file)
--- a/util.c
+++ b/util.c
@@ -429,24 +429,23 @@ void fprint_off(file, offset, width)
 {
     char buf[CHAR_BIT * sizeof (off_t)];
     char *p = buf + sizeof buf;
-    int negative = offset < 0;
+
     /* Don't negate offset here; it might overflow.  */
-    do {
-       int remainder = offset % 10;
-       int quotient = offset / 10;
-       if (offset < 0 && 0 < remainder) {
-           remainder -= 10;
-           quotient++;
-       }
-       *--p = (remainder < 0 ? -remainder : remainder) + '0';
-       width--;
-       offset = quotient;
-    } while (offset != 0);
-    for (width -= negative;  0 < width;  width--) {
-       putc (' ', file);
+    if (offset < 0) {
+       do
+         *--p = '0' - offset % 10;
+       while ((offset /= 10) != 0);
+
+       *--p = '-';
+    } else {
+       do
+         *--p = '0' + offset % 10;
+       while ((offset /= 10) != 0);
     }
-    if (negative) {
-       putc ('-', file);
+
+    width -= buf + sizeof buf - p;
+    while (0 < width--) {
+       putc (' ', file);
     }
     for (;  p < buf + sizeof buf;  p++)
        putc (*p, file);