summaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorRichard June2001-01-22 22:35:38 +0000
committerRichard June2001-01-22 22:35:38 +0000
commit6d0921cc0bb01b1d090285c487f8c1120dfa5d3a (patch)
tree97ed53aec9cbe3a3021804e9758abb3e04f05879 /utility.c
parent3b3f5c364a486dc2c081f0684a4315740f349be1 (diff)
downloadbusybox-6d0921cc0bb01b1d090285c487f8c1120dfa5d3a.zip
busybox-6d0921cc0bb01b1d090285c487f8c1120dfa5d3a.tar.gz
Add HUMAN_READABLE define for -m and -h support in du, df, and ls
Add support for -k in du, df, and ls(no define, it's for compatibliity with the GNU utils as bb does -k by default) Fix bug #1084
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/utility.c b/utility.c
index 9f524c3..bff589a 100644
--- a/utility.c
+++ b/utility.c
@@ -1770,6 +1770,27 @@ ssize_t safe_read(int fd, void *buf, size_t count)
}
#endif
+#ifdef BB_FEATURE_HUMAN_READABLE
+char *format(unsigned long val, unsigned long hr)
+{
+ static char str[10] = "\0";
+
+ if(val == 0)
+ return("0");
+ if(hr)
+ snprintf(str, 9, "%ld", val/hr);
+ else if(val >= GIGABYTE)
+ snprintf(str, 9, "%.1LfG", ((long double)(val)/GIGABYTE));
+ else if(val >= MEGABYTE)
+ snprintf(str, 9, "%.1LfM", ((long double)(val)/MEGABYTE));
+ else if(val >= KILOBYTE)
+ snprintf(str, 9, "%.1Lfk", ((long double)(val)/KILOBYTE));
+ else
+ snprintf(str, 9, "%ld", (val));
+ return(str);
+}
+#endif
+
/* END CODE */
/*
Local Variables: