index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | src/pacman/util.c | 35 |
diff --git a/src/pacman/util.c b/src/pacman/util.c index 49beb83d..1c3699ed 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -841,13 +841,13 @@ static alpm_list_t *create_verbose_row(pm_target_t *target, int dl_size) /* and size */ size -= target->remove ? alpm_pkg_get_isize(target->remove) : 0; size += target->install ? alpm_pkg_get_isize(target->install) : 0; - human_size = humanize_size(size, 'M', &label); + human_size = humanize_size(size, 'M', 2, &label); pm_asprintf(&str, "%.2f %s", human_size, label); ret = alpm_list_add(ret, str); if(dl_size) { size = target->install ? alpm_pkg_download_size(target->install) : 0; - human_size = humanize_size(size, 'M', &label); + human_size = humanize_size(size, 'M', 2, &label); if(size != 0) { pm_asprintf(&str, "%.2f %s", human_size, label); } else { @@ -931,21 +931,21 @@ static void _display_targets(alpm_list_t *targets, int verbose) free(str); if(dlsize > 0 || config->op_s_downloadonly) { - size = humanize_size(dlsize, 'M', &label); + size = humanize_size(dlsize, 'M', 2, &label); printf(_("Total Download Size: %.2f %s\n"), size, label); } if(!config->op_s_downloadonly) { if(isize > 0) { - size = humanize_size(isize, 'M', &label); + size = humanize_size(isize, 'M', 2, &label); printf(_("Total Installed Size: %.2f %s\n"), size, label); } if(rsize > 0 && isize == 0) { - size = humanize_size(rsize, 'M', &label); + size = humanize_size(rsize, 'M', 2, &label); printf(_("Total Removed Size: %.2f %s\n"), size, label); } /* only show this net value if different from raw installed size */ if(isize > 0 && rsize > 0) { - size = humanize_size(isize - rsize, 'M', &label); + size = humanize_size(isize - rsize, 'M', 2, &label); printf(_("Net Upgrade Size: %.2f %s\n"), size, label); } } @@ -1038,18 +1038,31 @@ static char *pkg_get_location(alpm_pkg_t *pkg) } } +/* a pow() implementation that is specialized for an integer base and small, + * positive-only integer exponents. */ +static double simple_pow(int base, int exp) +{ + double result = 1.0; + for(; exp > 0; exp--) { + result *= base; + } + return result; +} + /** Converts sizes in bytes into human readable units. * * @param bytes the size in bytes * @param target_unit '\0' or a short label. If equal to one of the short unit * labels ('B', 'K', ...) bytes is converted to target_unit; if '\0', the first * unit which will bring the value to below a threshold of 2048 will be chosen. - * @param long_labels whether to use short ("K") or long ("KiB") unit labels + * @param precision number of decimal places, ensures -0.0.0 gets rounded to + * 0.00; -1 if no rounding desired * @param label will be set to the appropriate unit label * * @return the size in the appropriate unit */ -double humanize_size(off_t bytes, const char target_unit, const char **label) +double humanize_size(off_t bytes, const char target_unit, int precision, + const char **label) { static const char *labels[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}; @@ -1071,6 +1084,12 @@ double humanize_size(off_t bytes, const char target_unit, const char **label) *label = labels[index]; } + /* fix FS#27924 so that it doesn't display negative zeroes */ + if(precision >= 0 && val < 0.0 && + val > (-0.5 / simple_pow(10, precision))) { + val = 0.0; + } + return val; } |