Subject: Re: bin/23600: df -h output miss unit letter for 10GB partitions
To: None <njoly@pasteur.fr>
From: Robert Elz <kre@munnari.OZ.AU>
List: current-users
Date: 11/30/2003 20:12:10
    Date:        Sun, 30 Nov 2003 13:30:16 +0100 (CET)
    From:        njoly@pasteur.fr
    Message-ID:  <20031130123016.D43BE7B37@cixy.dial.pasteur.fr>


  | >Description:
  | "Human-readable" output produced by df(1) can miss the unit letter,
  | especially for 10GB partitions :

Really, for partitions just slightly smaller (after overhears have been
removed, to leave available space) than 10 XB partitions, for any of the X's.

This is caused by rounding up after having decided what is the best
way to print the value -- here, starting with 9.99 G (or something
similar), deciding to print it with one character after the decimal
point (as it is < 10), then rounding the 9.99 to 10.0 ... then there
aren't enough spaces to add the unit designator.

The (truly ugly) patch below, applied to
	 /usr/src/lib/libc/gen/humanize_number.c
fixes the problem, but there must be a better way than the ugly goto!

kre

--- /usr/src/lib/libc/gen/humanize_number.c	2002-11-12 03:17:43.000000000 +0700
+++ humanize_number.c	2003-11-30 20:08:13.000000000 +0700
@@ -132,6 +132,8 @@
 		if ((s2 = (((bytes % 100) + 5) / 10)) == 10) {
 			s1++;
 			s2 = 0;
+			if (s1 >= 10)
+				goto toobig;
 		}
 		r = snprintf(buf, len, "%lld%s%lld%s%c%s",
 		    /* LONGLONG */
@@ -143,12 +145,14 @@
 		    "" : " ", (i == 0 && (flags & HN_B)) ? 'B' :
 		    prefixes[i], suffix);
 
-	} else
+	} else {
+   toobig:;
 		r = snprintf(buf, len, "%lld%s%c%s",
 		    /* LONGLONG */
 		    (long long)(sign * ((bytes + 50) / 100)),
 		    i == 0 || flags & HN_NOSPACE ? "" : " ", (i == 0 &&
 		    (flags & HN_B)) ? 'B' : prefixes[i], suffix);
+	}
 
 	return (r);
 }