libbb/human_readable.c: shrink; and reduce bss usage
also, move smart_ulltoaN there and comment usage locations
function old new delta
static.unit_chars 7 9 +2
utoa_to_buf 110 108 -2
make_human_readable_str 262 258 -4
fallbackSort 1723 1719 -4
static.fmt 97 92 -5
static.fmt_tenths 10 - -10
static.str 21 4 -17
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/5 up/down: 2/-42) Total: -40 bytes
text data bss dec hex filename
820981 453 6932 828366 ca3ce busybox_old
820968 453 6916 828337 ca3b1 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/coreutils/df.c b/coreutils/df.c
index c37b188..624ad94 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -92,7 +92,10 @@
if (disp_units_hdr == NULL) {
#if ENABLE_FEATURE_HUMAN_READABLE
disp_units_hdr = xasprintf("%s-blocks",
- make_human_readable_str(df_disp_hr, 0, !!(opt & OPT_POSIX)));
+ /* print df_disp_hr, show no fractionals,
+ * use suffixes if OPT_POSIX is set in opt */
+ make_human_readable_str(df_disp_hr, 0, !!(opt & OPT_POSIX))
+ );
#else
disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
#endif
@@ -189,21 +192,27 @@
#if ENABLE_FEATURE_HUMAN_READABLE
printf(" %9s ",
+ /* f_blocks x f_bsize / df_disp_hr, show one fractional,
+ * use suffixes if df_disp_hr == 0 */
make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr));
printf(" %9s " + 1,
+ /* EXPR x f_bsize / df_disp_hr, show one fractional,
+ * use suffixes if df_disp_hr == 0 */
make_human_readable_str((s.f_blocks - s.f_bfree),
s.f_bsize, df_disp_hr));
printf("%9s %3u%% %s\n",
- make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
- blocks_percent_used, mount_point);
+ /* f_bavail x f_bsize / df_disp_hr, show one fractional,
+ * use suffixes if df_disp_hr == 0 */
+ make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
+ blocks_percent_used, mount_point);
#else
printf(" %9lu %9lu %9lu %3u%% %s\n",
- kscale(s.f_blocks, s.f_bsize),
- kscale(s.f_blocks - s.f_bfree, s.f_bsize),
- kscale(s.f_bavail, s.f_bsize),
- blocks_percent_used, mount_point);
+ kscale(s.f_blocks, s.f_bsize),
+ kscale(s.f_blocks - s.f_bfree, s.f_bsize),
+ kscale(s.f_bavail, s.f_bsize),
+ blocks_percent_used, mount_point);
#endif
}
}