]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Remove comma after last item in enum.
authorJim Meyering <jim@meyering.net>
Thu, 1 Feb 1996 04:13:26 +0000 (04:13 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 1 Feb 1996 04:13:26 +0000 (04:13 +0000)
(human_readable): Fix off-by-one error that converted
1024*1024 to 1024K rather than 1G.  Describe the function.

src/du.c

index 24fe8969db04e56e37b0c8879efd3c8c0bf7e71b..5757be63c939248dad5f97a9546537bda91e1477 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -152,7 +152,7 @@ enum output_size
   size_blocks,                 /* 512-byte blocks. */
   size_kilobytes,              /* 1K blocks. */
   size_megabytes,              /* 1024K blocks. */
-  size_bytes,                  /* 1-byte blocks. */
+  size_bytes                   /* 1-byte blocks. */
 };
 
 /* human style output */
@@ -351,6 +351,15 @@ main (int argc, char **argv)
   exit (exit_status);
 }
 
+/* Convert N_BYTES to a more readable string than %d would.
+   Most people visually process strings of 3-4 digits effectively,
+   but longer strings of digits are more prone to misinterpretation.
+   Hence, converting to an abbreviated form usually improves readability.
+   Use a suffix indicating multiples of 1024 (K), 1024*1024 (M), and
+   1024*1024*1024 (G).  For example, 8500 would be converted to 8.3K,
+   133456345 to 127M, 56990456345 to 53G, and so on.  Numbers smaller
+   than 1024 aren't modified.  */
+
 static char *
 human_readable (int n_bytes, char *buf, int buf_len)
 {
@@ -363,17 +372,17 @@ human_readable (int n_bytes, char *buf, int buf_len)
   p = buf;
   amt = n_bytes;
 
-  if (amt > 1024 * 1024 * 1024)
+  if (amt >= 1024 * 1024 * 1024)
     {
       amt /= (1024 * 1024 * 1024);
       suffix = "G";
     }
-  else if (amt > 1024 * 1024)
+  else if (amt >= 1024 * 1024)
     {
       amt /= (1024 * 1024);
       suffix = "M";
     }
-  else if (amt > 1024)
+  else if (amt >= 1024)
     {
       amt /= 1024;
       suffix = "K";