aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-06-13 08:02:45 +0000
committerEric Andersen <andersen@codepoet.org>2001-06-13 08:02:45 +0000
commitf429baca868b7f62ffdeefbfce41abd677f97876 (patch)
tree64925420925deb361a2024b9b362e5c987334124 /coreutils
parent17822cd60aaf9333a9895494edcf03a0037de54c (diff)
downloadbusybox-f429baca868b7f62ffdeefbfce41abd677f97876.tar.gz
I reworked make_human_readable_str so it now has a sane interface,
and then fixed up df, du, and ls to use the new interface. I also fixed up some formatting issues in ls while I was in there. -Erik
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/df.c31
-rw-r--r--coreutils/du.c15
-rw-r--r--coreutils/ls.c11
3 files changed, 15 insertions, 42 deletions
diff --git a/coreutils/df.c b/coreutils/df.c
index df6874433..6a81086cb 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -32,7 +32,7 @@
extern const char mtab_file[]; /* Defined in utility.c */
#ifdef BB_FEATURE_HUMAN_READABLE
-static unsigned long df_disp_hr = KILOBYTE;
+static unsigned long df_disp_hr = 1;
#endif
static int do_df(char *device, const char *mount_point)
@@ -40,9 +40,6 @@ static int do_df(char *device, const char *mount_point)
struct statfs s;
long blocks_used;
long blocks_percent_used;
-#ifdef BB_FEATURE_HUMAN_READABLE
- long base;
-#endif
if (statfs(mount_point, &s) != 0) {
perror_msg("%s", mount_point);
@@ -65,27 +62,15 @@ static int do_df(char *device, const char *mount_point)
return FALSE;
}
#ifdef BB_FEATURE_HUMAN_READABLE
- switch (df_disp_hr) {
- case MEGABYTE:
- base = KILOBYTE;
- break;
- case KILOBYTE:
- base = 1;
- break;
- default:
- base = 0;
- }
printf("%-20s %9s ", device,
- make_human_readable_str((unsigned long)(s.f_blocks *
- (s.f_bsize/(double)KILOBYTE)), base));
+ make_human_readable_str(s.f_blocks, s.f_bsize/KILOBYTE, df_disp_hr));
+
printf("%9s ",
- make_human_readable_str((unsigned long)(
- (s.f_blocks - s.f_bfree) *
- (s.f_bsize/(double)KILOBYTE)), base));
+ make_human_readable_str( (s.f_blocks - s.f_bfree), s.f_bsize/KILOBYTE, df_disp_hr));
+
printf("%9s %3ld%% %s\n",
- make_human_readable_str((unsigned long)(s.f_bavail *
- (s.f_bsize/(double)KILOBYTE)), base),
- blocks_percent_used, mount_point);
+ make_human_readable_str(s.f_bavail, s.f_bsize/KILOBYTE, df_disp_hr),
+ blocks_percent_used, mount_point);
#else
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
@@ -119,7 +104,7 @@ extern int df_main(int argc, char **argv)
strcpy(disp_units_hdr, " Size");
break;
case 'm':
- df_disp_hr = MEGABYTE;
+ df_disp_hr = KILOBYTE;
strcpy(disp_units_hdr, "1M-blocks");
break;
#endif
diff --git a/coreutils/du.c b/coreutils/du.c
index fd19855e1..1966e3559 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -46,19 +46,8 @@ static Display *print;
static void print_normal(long size, char *filename)
{
- unsigned long base;
#ifdef BB_FEATURE_HUMAN_READABLE
- switch (disp_hr) {
- case MEGABYTE:
- base = KILOBYTE;
- break;
- case KILOBYTE:
- base = 1;
- break;
- default:
- base = 0;
- }
- printf("%s\t%s\n", make_human_readable_str(size, base), filename);
+ printf("%s\t%s\n", make_human_readable_str(size<<10, 1, disp_hr), filename);
#else
printf("%ld\t%s\n", size, filename);
#endif
@@ -259,7 +248,7 @@ int du_main(int argc, char **argv)
return status;
}
-/* $Id: du.c,v 1.48 2001/06/01 21:47:15 andersen Exp $ */
+/* $Id: du.c,v 1.49 2001/06/13 08:02:44 andersen Exp $ */
/*
Local Variables:
c-file-style: "linux"
diff --git a/coreutils/ls.c b/coreutils/ls.c
index ec8e216fa..c54b6a42f 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -610,8 +610,8 @@ static int list_single(struct dnode *dn)
break;
case LIST_BLOCKS:
#ifdef BB_FEATURE_HUMAN_READABLE
- fprintf(stdout, "%5s ", make_human_readable_str(dn->dstat.st_blocks>>1,
- (ls_disp_hr==TRUE)? 0: 1));
+ fprintf(stdout, "%4s ", make_human_readable_str(dn->dstat.st_blocks>>1,
+ KILOBYTE, (ls_disp_hr==TRUE)? 0: 1));
#else
#if _FILE_OFFSET_BITS == 64
printf("%4lld ", dn->dstat.st_blocks>>1);
@@ -622,7 +622,7 @@ static int list_single(struct dnode *dn)
column += 5;
break;
case LIST_MODEBITS:
- printf("%10s", (char *)mode_string(dn->dstat.st_mode));
+ printf("%-10s ", (char *)mode_string(dn->dstat.st_mode));
column += 10;
break;
case LIST_NLINKS:
@@ -634,7 +634,7 @@ static int list_single(struct dnode *dn)
my_getpwuid(scratch, dn->dstat.st_uid);
printf("%-8.8s ", scratch);
my_getgrgid(scratch, dn->dstat.st_gid);
- printf("%-8.8s", scratch);
+ printf("%-8.8s ", scratch);
column += 17;
break;
#endif
@@ -649,8 +649,7 @@ static int list_single(struct dnode *dn)
} else {
#ifdef BB_FEATURE_HUMAN_READABLE
if (ls_disp_hr==TRUE) {
- fprintf(stdout, "%9s ", make_human_readable_str(
- dn->dstat.st_size>>10, 0));
+ fprintf(stdout, "%8s ", make_human_readable_str(dn->dstat.st_size, 1, 0));
} else
#endif
{