summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley2001-03-07 17:42:07 +0000
committerMark Whitley2001-03-07 17:42:07 +0000
commitae5612ca6e74ba251cd10fc853dcf9694c0fecf1 (patch)
treeba3e50459f4b4ae476ce19e797c68c5e6de055e0
parentae20128e9f7a7d31629079068b04cf7119cc40df (diff)
downloadbusybox-ae5612ca6e74ba251cd10fc853dcf9694c0fecf1.zip
busybox-ae5612ca6e74ba251cd10fc853dcf9694c0fecf1.tar.gz
Some minor cleanups to df.c. Also, with Erik's blessing, changed name of
'format' function to 'make_human_readable_str'.
-rw-r--r--busybox.h2
-rw-r--r--coreutils/df.c69
-rw-r--r--coreutils/du.c6
-rw-r--r--coreutils/ls.c6
-rw-r--r--df.c69
-rw-r--r--du.c6
-rw-r--r--include/busybox.h2
-rw-r--r--ls.c6
-rw-r--r--utility.c2
9 files changed, 87 insertions, 81 deletions
diff --git a/busybox.h b/busybox.h
index 9993209..573cce1 100644
--- a/busybox.h
+++ b/busybox.h
@@ -233,7 +233,7 @@ extern int sysinfo (struct sysinfo* info);
#endif
#ifdef BB_FEATURE_HUMAN_READABLE
-const char *format(unsigned long val, unsigned long hr);
+const char *make_human_readable_str(unsigned long val, unsigned long hr);
#endif
#define KILOBYTE 1024
#define MEGABYTE (KILOBYTE*1024)
diff --git a/coreutils/df.c b/coreutils/df.c
index 9f8770f..485076f 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -31,10 +31,10 @@
extern const char mtab_file[]; /* Defined in utility.c */
#ifdef BB_FEATURE_HUMAN_READABLE
-static unsigned long disp_hr = KILOBYTE;
+static unsigned long df_disp_hr = KILOBYTE;
#endif
-static int df(char *device, const char *mountPoint)
+static int do_df(char *device, const char *mount_point)
{
struct statfs s;
long blocks_used;
@@ -43,8 +43,8 @@ static int df(char *device, const char *mountPoint)
long base;
#endif
- if (statfs(mountPoint, &s) != 0) {
- perror_msg("%s", mountPoint);
+ if (statfs(mount_point, &s) != 0) {
+ perror_msg("%s", mount_point);
return FALSE;
}
@@ -61,8 +61,8 @@ static int df(char *device, const char *mountPoint)
* or leaves device alone if it can't find it */
find_real_root_device_name( device);
}
- #ifdef BB_FEATURE_HUMAN_READABLE
- switch (disp_hr) {
+#ifdef BB_FEATURE_HUMAN_READABLE
+ switch (df_disp_hr) {
case MEGABYTE:
base = KILOBYTE;
break;
@@ -73,19 +73,19 @@ static int df(char *device, const char *mountPoint)
base = 0;
}
printf("%-20s %9s ", device,
- format(s.f_blocks * (s.f_bsize/KILOBYTE), base));
+ make_human_readable_str(s.f_blocks * (s.f_bsize/KILOBYTE), base));
printf("%9s ",
- format((s.f_blocks - s.f_bfree) * (s.f_bsize/KILOBYTE), base));
+ make_human_readable_str((s.f_blocks - s.f_bfree) * (s.f_bsize/KILOBYTE), base));
printf("%9s %3ld%% %s\n",
- format(s.f_bavail * (s.f_bsize/KILOBYTE), base),
- blocks_percent_used, mountPoint);
+ make_human_readable_str(s.f_bavail * (s.f_bsize/KILOBYTE), base),
+ blocks_percent_used, mount_point);
#else
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long) (s.f_blocks * (s.f_bsize / KILOBYTE)),
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / KILOBYTE)),
(long) (s.f_bavail * (s.f_bsize / KILOBYTE)),
- blocks_percent_used, mountPoint);
+ blocks_percent_used, mount_point);
#endif
}
@@ -97,60 +97,61 @@ extern int df_main(int argc, char **argv)
int status = EXIT_SUCCESS;
int opt = 0;
int i = 0;
+ char disp_units_hdr[80] = "1k-blocks"; /* default display is kilobytes */
- while ((opt = getopt(argc, argv,
+ while ((opt = getopt(argc, argv, "k"
#ifdef BB_FEATURE_HUMAN_READABLE
"hm"
#endif
- "k"
)) > 0)
{
switch (opt) {
#ifdef BB_FEATURE_HUMAN_READABLE
- case 'h': disp_hr = 0; break;
- case 'm': disp_hr = MEGABYTE; break;
+ case 'h':
+ df_disp_hr = 0;
+ strcpy(disp_units_hdr, " Size");
+ break;
+ case 'm':
+ df_disp_hr = MEGABYTE;
+ strcpy(disp_units_hdr, "1M-blocks");
+ break;
#endif
- case 'k': break;
+ case 'k':
+ /* default display is kilobytes */
+ break;
default:
show_usage();
}
}
- printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
-#ifdef BB_FEATURE_HUMAN_READABLE
- (KILOBYTE == disp_hr) ? "1k-blocks" :
- (MEGABYTE == disp_hr) ? "1M-blocks" : " Size",
-#else
- "1k-blocks",
-#endif
+ printf("%-20s %-14s %s %s %s %s\n", "Filesystem", disp_units_hdr,
"Used", "Available", "Use%", "Mounted on");
-
if(optind < argc) {
- struct mntent *mountEntry;
+ struct mntent *mount_entry;
for(i = optind; i < argc; i++)
{
- if ((mountEntry = find_mount_point(argv[i], mtab_file)) == 0) {
+ if ((mount_entry = find_mount_point(argv[i], mtab_file)) == 0) {
error_msg("%s: can't find mount point.", argv[i]);
status = EXIT_FAILURE;
- } else if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
+ } else if (!do_df(mount_entry->mnt_fsname, mount_entry->mnt_dir))
status = EXIT_FAILURE;
}
} else {
- FILE *mountTable;
- struct mntent *mountEntry;
+ FILE *mount_table;
+ struct mntent *mount_entry;
- mountTable = setmntent(mtab_file, "r");
- if (mountTable == 0) {
+ mount_table = setmntent(mtab_file, "r");
+ if (mount_table == 0) {
perror_msg("%s", mtab_file);
return EXIT_FAILURE;
}
- while ((mountEntry = getmntent(mountTable))) {
- if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
+ while ((mount_entry = getmntent(mount_table))) {
+ if (!do_df(mount_entry->mnt_fsname, mount_entry->mnt_dir))
status = EXIT_FAILURE;
}
- endmntent(mountTable);
+ endmntent(mount_table);
}
return status;
diff --git a/coreutils/du.c b/coreutils/du.c
index 36c4de2..17ecfde 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -60,7 +60,7 @@ static void print_normal(long size, char *filename)
default:
base = 0;
}
-printf("%s\t%s\n", format(size, base), filename);
+ printf("%s\t%s\n", make_human_readable_str(size, base), filename);
#else
printf("%ld\t%s\n", size, filename);
#endif
@@ -69,7 +69,7 @@ printf("%s\t%s\n", format(size, base), filename);
static void print_summary(long size, char *filename)
{
if (du_depth == 1) {
-printf("summary\n");
+ printf("summary\n");
print_normal(size, filename);
}
}
@@ -196,7 +196,7 @@ int du_main(int argc, char **argv)
return status;
}
-/* $Id: du.c,v 1.41 2001/03/07 06:04:08 andersen Exp $ */
+/* $Id: du.c,v 1.42 2001/03/07 17:42:07 markw Exp $ */
/*
Local Variables:
c-file-style: "linux"
diff --git a/coreutils/ls.c b/coreutils/ls.c
index f9e0b25..a8d7b18 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -610,7 +610,8 @@ int list_single(struct dnode *dn)
break;
case LIST_BLOCKS:
#ifdef BB_FEATURE_HUMAN_READABLE
- fprintf(stdout, "%5s ", format(dn->dstat.st_blocks>>1, (ls_disp_hr==TRUE)? 0: 1));
+ fprintf(stdout, "%5s ", make_human_readable_str(dn->dstat.st_blocks>>1,
+ (ls_disp_hr==TRUE)? 0: 1));
#else
#if _FILE_OFFSET_BITS == 64
printf("%4lld ", dn->dstat.st_blocks>>1);
@@ -647,7 +648,8 @@ int list_single(struct dnode *dn)
printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
} else {
#ifdef BB_FEATURE_HUMAN_READABLE
- fprintf(stdout, "%9s ", format(dn->dstat.st_size, (ls_disp_hr==TRUE)? 0: 1));
+ fprintf(stdout, "%9s ", make_human_readable_str(dn->dstat.st_size,
+ (ls_disp_hr==TRUE)? 0: 1));
#else
#if _FILE_OFFSET_BITS == 64
printf("%9lld ", dn->dstat.st_size>>1);
diff --git a/df.c b/df.c
index 9f8770f..485076f 100644
--- a/df.c
+++ b/df.c
@@ -31,10 +31,10 @@
extern const char mtab_file[]; /* Defined in utility.c */
#ifdef BB_FEATURE_HUMAN_READABLE
-static unsigned long disp_hr = KILOBYTE;
+static unsigned long df_disp_hr = KILOBYTE;
#endif
-static int df(char *device, const char *mountPoint)
+static int do_df(char *device, const char *mount_point)
{
struct statfs s;
long blocks_used;
@@ -43,8 +43,8 @@ static int df(char *device, const char *mountPoint)
long base;
#endif
- if (statfs(mountPoint, &s) != 0) {
- perror_msg("%s", mountPoint);
+ if (statfs(mount_point, &s) != 0) {
+ perror_msg("%s", mount_point);
return FALSE;
}
@@ -61,8 +61,8 @@ static int df(char *device, const char *mountPoint)
* or leaves device alone if it can't find it */
find_real_root_device_name( device);
}
- #ifdef BB_FEATURE_HUMAN_READABLE
- switch (disp_hr) {
+#ifdef BB_FEATURE_HUMAN_READABLE
+ switch (df_disp_hr) {
case MEGABYTE:
base = KILOBYTE;
break;
@@ -73,19 +73,19 @@ static int df(char *device, const char *mountPoint)
base = 0;
}
printf("%-20s %9s ", device,
- format(s.f_blocks * (s.f_bsize/KILOBYTE), base));
+ make_human_readable_str(s.f_blocks * (s.f_bsize/KILOBYTE), base));
printf("%9s ",
- format((s.f_blocks - s.f_bfree) * (s.f_bsize/KILOBYTE), base));
+ make_human_readable_str((s.f_blocks - s.f_bfree) * (s.f_bsize/KILOBYTE), base));
printf("%9s %3ld%% %s\n",
- format(s.f_bavail * (s.f_bsize/KILOBYTE), base),
- blocks_percent_used, mountPoint);
+ make_human_readable_str(s.f_bavail * (s.f_bsize/KILOBYTE), base),
+ blocks_percent_used, mount_point);
#else
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long) (s.f_blocks * (s.f_bsize / KILOBYTE)),
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / KILOBYTE)),
(long) (s.f_bavail * (s.f_bsize / KILOBYTE)),
- blocks_percent_used, mountPoint);
+ blocks_percent_used, mount_point);
#endif
}
@@ -97,60 +97,61 @@ extern int df_main(int argc, char **argv)
int status = EXIT_SUCCESS;
int opt = 0;
int i = 0;
+ char disp_units_hdr[80] = "1k-blocks"; /* default display is kilobytes */
- while ((opt = getopt(argc, argv,
+ while ((opt = getopt(argc, argv, "k"
#ifdef BB_FEATURE_HUMAN_READABLE
"hm"
#endif
- "k"
)) > 0)
{
switch (opt) {
#ifdef BB_FEATURE_HUMAN_READABLE
- case 'h': disp_hr = 0; break;
- case 'm': disp_hr = MEGABYTE; break;
+ case 'h':
+ df_disp_hr = 0;
+ strcpy(disp_units_hdr, " Size");
+ break;
+ case 'm':
+ df_disp_hr = MEGABYTE;
+ strcpy(disp_units_hdr, "1M-blocks");
+ break;
#endif
- case 'k': break;
+ case 'k':
+ /* default display is kilobytes */
+ break;
default:
show_usage();
}
}
- printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
-#ifdef BB_FEATURE_HUMAN_READABLE
- (KILOBYTE == disp_hr) ? "1k-blocks" :
- (MEGABYTE == disp_hr) ? "1M-blocks" : " Size",
-#else
- "1k-blocks",
-#endif
+ printf("%-20s %-14s %s %s %s %s\n", "Filesystem", disp_units_hdr,
"Used", "Available", "Use%", "Mounted on");
-
if(optind < argc) {
- struct mntent *mountEntry;
+ struct mntent *mount_entry;
for(i = optind; i < argc; i++)
{
- if ((mountEntry = find_mount_point(argv[i], mtab_file)) == 0) {
+ if ((mount_entry = find_mount_point(argv[i], mtab_file)) == 0) {
error_msg("%s: can't find mount point.", argv[i]);
status = EXIT_FAILURE;
- } else if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
+ } else if (!do_df(mount_entry->mnt_fsname, mount_entry->mnt_dir))
status = EXIT_FAILURE;
}
} else {
- FILE *mountTable;
- struct mntent *mountEntry;
+ FILE *mount_table;
+ struct mntent *mount_entry;
- mountTable = setmntent(mtab_file, "r");
- if (mountTable == 0) {
+ mount_table = setmntent(mtab_file, "r");
+ if (mount_table == 0) {
perror_msg("%s", mtab_file);
return EXIT_FAILURE;
}
- while ((mountEntry = getmntent(mountTable))) {
- if (!df(mountEntry->mnt_fsname, mountEntry->mnt_dir))
+ while ((mount_entry = getmntent(mount_table))) {
+ if (!do_df(mount_entry->mnt_fsname, mount_entry->mnt_dir))
status = EXIT_FAILURE;
}
- endmntent(mountTable);
+ endmntent(mount_table);
}
return status;
diff --git a/du.c b/du.c
index 36c4de2..17ecfde 100644
--- a/du.c
+++ b/du.c
@@ -60,7 +60,7 @@ static void print_normal(long size, char *filename)
default:
base = 0;
}
-printf("%s\t%s\n", format(size, base), filename);
+ printf("%s\t%s\n", make_human_readable_str(size, base), filename);
#else
printf("%ld\t%s\n", size, filename);
#endif
@@ -69,7 +69,7 @@ printf("%s\t%s\n", format(size, base), filename);
static void print_summary(long size, char *filename)
{
if (du_depth == 1) {
-printf("summary\n");
+ printf("summary\n");
print_normal(size, filename);
}
}
@@ -196,7 +196,7 @@ int du_main(int argc, char **argv)
return status;
}
-/* $Id: du.c,v 1.41 2001/03/07 06:04:08 andersen Exp $ */
+/* $Id: du.c,v 1.42 2001/03/07 17:42:07 markw Exp $ */
/*
Local Variables:
c-file-style: "linux"
diff --git a/include/busybox.h b/include/busybox.h
index 9993209..573cce1 100644
--- a/include/busybox.h
+++ b/include/busybox.h
@@ -233,7 +233,7 @@ extern int sysinfo (struct sysinfo* info);
#endif
#ifdef BB_FEATURE_HUMAN_READABLE
-const char *format(unsigned long val, unsigned long hr);
+const char *make_human_readable_str(unsigned long val, unsigned long hr);
#endif
#define KILOBYTE 1024
#define MEGABYTE (KILOBYTE*1024)
diff --git a/ls.c b/ls.c
index f9e0b25..a8d7b18 100644
--- a/ls.c
+++ b/ls.c
@@ -610,7 +610,8 @@ int list_single(struct dnode *dn)
break;
case LIST_BLOCKS:
#ifdef BB_FEATURE_HUMAN_READABLE
- fprintf(stdout, "%5s ", format(dn->dstat.st_blocks>>1, (ls_disp_hr==TRUE)? 0: 1));
+ fprintf(stdout, "%5s ", make_human_readable_str(dn->dstat.st_blocks>>1,
+ (ls_disp_hr==TRUE)? 0: 1));
#else
#if _FILE_OFFSET_BITS == 64
printf("%4lld ", dn->dstat.st_blocks>>1);
@@ -647,7 +648,8 @@ int list_single(struct dnode *dn)
printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
} else {
#ifdef BB_FEATURE_HUMAN_READABLE
- fprintf(stdout, "%9s ", format(dn->dstat.st_size, (ls_disp_hr==TRUE)? 0: 1));
+ fprintf(stdout, "%9s ", make_human_readable_str(dn->dstat.st_size,
+ (ls_disp_hr==TRUE)? 0: 1));
#else
#if _FILE_OFFSET_BITS == 64
printf("%9lld ", dn->dstat.st_size>>1);
diff --git a/utility.c b/utility.c
index 0ace3eb..7c7af15 100644
--- a/utility.c
+++ b/utility.c
@@ -1798,7 +1798,7 @@ ssize_t safe_read(int fd, void *buf, size_t count)
#endif
#ifdef BB_FEATURE_HUMAN_READABLE
-const char *format(unsigned long val, unsigned long hr)
+const char *make_human_readable_str(unsigned long val, unsigned long hr)
{
int i=0;
static char str[10] = "\0";