aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-04-03 23:14:29 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-04-03 23:14:29 +0000
commit810010a425ba2cbe982374e466eb2c0e3ecfe22a (patch)
tree93fed8e5cfa179b95e937f5a754a3ba1a9587422
parentee7f2282d655efc55700ecac2482f78a11a7b55f (diff)
downloadbusybox-w32-810010a425ba2cbe982374e466eb2c0e3ecfe22a.tar.gz
busybox-w32-810010a425ba2cbe982374e466eb2c0e3ecfe22a.tar.bz2
busybox-w32-810010a425ba2cbe982374e466eb2c0e3ecfe22a.zip
Place a temporary bandaid on the ls/du/df human-readable issue. This method is
not going to scale up as well as I would like, and Matt Kraai and I have discussed a better long term solution. But for now this will at least make all the human-readable apps give correct answers. Please test the human readable/non-human readable options on your systems!!! -Erik git-svn-id: svn://busybox.net/trunk/busybox@2235 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--coreutils/ls.c15
-rw-r--r--libbb/human_readable.c47
-rw-r--r--ls.c15
3 files changed, 46 insertions, 31 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 86691fdaf..49470e9f7 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -648,15 +648,18 @@ static int list_single(struct dnode *dn)
648 printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev)); 648 printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
649 } else { 649 } else {
650#ifdef BB_FEATURE_HUMAN_READABLE 650#ifdef BB_FEATURE_HUMAN_READABLE
651 fprintf(stdout, "%9s ", make_human_readable_str(dn->dstat.st_size>>10, 651 if (ls_disp_hr==TRUE) {
652 (ls_disp_hr==TRUE)? 0: 1)); 652 fprintf(stdout, "%9s ", make_human_readable_str(
653#else 653 dn->dstat.st_size>>10, 0));
654 } else
655#endif
656 {
654#if _FILE_OFFSET_BITS == 64 657#if _FILE_OFFSET_BITS == 64
655 printf("%9lld ", dn->dstat.st_size); 658 printf("%9lld ", dn->dstat.st_size);
656#else 659#else
657 printf("%9ld ", dn->dstat.st_size); 660 printf("%9ld ", dn->dstat.st_size);
658#endif
659#endif 661#endif
662 }
660 } 663 }
661 column += 10; 664 column += 10;
662 break; 665 break;
diff --git a/libbb/human_readable.c b/libbb/human_readable.c
index 36783fac7..ff2175175 100644
--- a/libbb/human_readable.c
+++ b/libbb/human_readable.c
@@ -28,26 +28,35 @@
28#include <stdio.h> 28#include <stdio.h>
29#include "libbb.h" 29#include "libbb.h"
30 30
31static char buffer[10];
32static const char *suffixes[] = { "", "k", "M", "G", "T" };
33 31
34const char *make_human_readable_str(unsigned long val, unsigned long not_hr)
35{
36 int suffix, base;
37 32
38 if (not_hr) 33const char *make_human_readable_str(unsigned long val, unsigned long hr)
39 sprintf(buffer, "%lu", val); 34{
40 else 35 int i=0;
41 for (suffix = 0, base = 1; suffix < 5; suffix++, base <<= 10) { 36 static char str[10] = "\0";
42 if (val < (base << 10)) { 37 static const char strings[] = { 'k', 'M', 'G', 'T', 0 };
43 if (suffix && val < 10 * base) 38 unsigned long divisor = 1;
44 sprintf(buffer, "%lu.%lu%s", val / base,
45 (val % base) * 10 / base, suffixes[suffix]);
46 else
47 sprintf(buffer, "%lu%s", val / base, suffixes[suffix]);
48 break;
49 }
50 }
51 39
52 return buffer; 40 if(val == 0)
41 return("0");
42 if(hr)
43 snprintf(str, 9, "%ld", val/hr);
44 else {
45 while(val >= divisor && i <= 4) {
46 divisor=divisor<<10, i++;
47 }
48 divisor=divisor>>10, i--;
49 snprintf(str, 9, "%.1Lf%c", (long double)(val)/divisor, strings[i]);
50 }
51 return(str);
53} 52}
53
54
55/* END CODE */
56/*
57Local Variables:
58c-file-style: "linux"
59c-basic-offset: 4
60tab-width: 4
61End:
62*/
diff --git a/ls.c b/ls.c
index 86691fdaf..49470e9f7 100644
--- a/ls.c
+++ b/ls.c
@@ -648,15 +648,18 @@ static int list_single(struct dnode *dn)
648 printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev)); 648 printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
649 } else { 649 } else {
650#ifdef BB_FEATURE_HUMAN_READABLE 650#ifdef BB_FEATURE_HUMAN_READABLE
651 fprintf(stdout, "%9s ", make_human_readable_str(dn->dstat.st_size>>10, 651 if (ls_disp_hr==TRUE) {
652 (ls_disp_hr==TRUE)? 0: 1)); 652 fprintf(stdout, "%9s ", make_human_readable_str(
653#else 653 dn->dstat.st_size>>10, 0));
654 } else
655#endif
656 {
654#if _FILE_OFFSET_BITS == 64 657#if _FILE_OFFSET_BITS == 64
655 printf("%9lld ", dn->dstat.st_size); 658 printf("%9lld ", dn->dstat.st_size);
656#else 659#else
657 printf("%9ld ", dn->dstat.st_size); 660 printf("%9ld ", dn->dstat.st_size);
658#endif
659#endif 661#endif
662 }
660 } 663 }
661 column += 10; 664 column += 10;
662 break; 665 break;