Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/pacman/package.c
diff options
context:
space:
mode:
authorJakob Gruber <jakob.gruber@gmail.com>2011-02-20 19:38:32 +0100
committerDan McGee <dan@archlinux.org>2011-04-20 17:29:32 -0500
commit3c8a448a2ff6b433059b1beb3a35cfd67c148d0c (patch)
treed97cf667508787562f35f0125f31396d63bee495 /src/pacman/package.c
parentdcb6fb224dd3ac91c08369e9fbff12349b96e545 (diff)
Add a utility function to humanize sizes
Converts the given size in bytes in two possible ways: 1) target_unit is specified (!= 0): size is converted to target unit. 2) target_unit is not specified (== '\0'): size is converted to the first unit which will bring size to below 2048. If specified, label will point to the long label ('MB') if long_labels is set or the short label ('M') if it is not. Dan: use '\0' rather than 0 for the special value as a matter of coding style for char variables. Signed-off-by: Jakob Gruber <jakob.gruber@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman/package.c')
-rw-r--r--src/pacman/package.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/pacman/package.c b/src/pacman/package.c
index d8dde695..e3a4614a 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -51,6 +51,8 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
const char *reason;
time_t bdate, idate;
char bdatestr[50] = "", idatestr[50] = "";
+ const char *label;
+ double size;
const alpm_list_t *i;
alpm_list_t *requiredby = NULL, *depstrings = NULL;
@@ -105,17 +107,17 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
}
list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg));
list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg));
+
+ size = humanize_size(alpm_pkg_get_size(pkg), 'K', 1, &label);
if(level < 0) {
- printf(_("Download Size : %6.2f K\n"),
- (double)alpm_pkg_get_size(pkg) / 1024.0);
- }
- if(level == 0) {
- printf(_("Compressed Size: %6.2f K\n"),
- (double)alpm_pkg_get_size(pkg) / 1024.0);
+ printf(_("Download Size : %6.2f %s\n"), size, label);
+ } else if(level == 0) {
+ printf(_("Compressed Size: %6.2f %s\n"), size, label);
}
- printf(_("Installed Size : %6.2f K\n"),
- (double)alpm_pkg_get_isize(pkg) / 1024.0);
+ size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 1, &label);
+ printf(_("Installed Size : %6.2f %s\n"), size, label);
+
string_display(_("Packager :"), alpm_pkg_get_packager(pkg));
string_display(_("Architecture :"), alpm_pkg_get_arch(pkg));
string_display(_("Build Date :"), bdatestr);