summaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
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: