libxbps::xbps_humanize_number(): use common values and hide implementation details from API.

So now its prototype is the following:

int xbps_humanize_number(char *buf, int64_t bytes)

It is a wrapper around NetBSD's humanize_number(3) which uses 6 digits for max
length, HN_AUTOSCALE and HN_NOSPACE|HN_DECIMAL. All users have been updated.
This commit is contained in:
Juan RP
2011-01-18 23:10:07 +01:00
parent e2b55c90be
commit 992e8c6a14
5 changed files with 42 additions and 42 deletions

View File

@@ -195,7 +195,7 @@ show_transaction_sizes(struct transaction *trans)
prop_object_t obj;
uint64_t dlsize = 0, instsize = 0;
const char *tract;
char size[64];
char size[8];
bool trans_inst, trans_up, trans_conf;
trans_inst = trans_up = trans_conf = false;
@@ -240,15 +240,13 @@ show_transaction_sizes(struct transaction *trans)
prop_dictionary_get_uint64(trans->dict, "total-download-size", &dlsize);
prop_dictionary_get_uint64(trans->dict, "total-installed-size",
&instsize);
if (xbps_humanize_number(size, 5, (int64_t)dlsize,
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE) == -1) {
if (xbps_humanize_number(size, (int64_t)dlsize) == -1) {
fprintf(stderr, "xbps-bin: error: humanize_number returns "
"%s\n", strerror(errno));
return -1;
}
printf("Total download size: %sB\n", size);
if (xbps_humanize_number(size, 5, (int64_t)instsize,
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE) == -1) {
if (xbps_humanize_number(size, (int64_t)instsize) == -1) {
fprintf(stderr, "xbps-bin: error: humanize_number2 returns "
"%s\n", strerror(errno));
return -1;

View File

@@ -39,17 +39,16 @@ void
show_pkg_info_only_repo(prop_dictionary_t dict)
{
prop_object_t obj;
char size[64];
int rv = 0;
char size[8];
int rv;
obj = prop_dictionary_get(dict, "filename");
if (prop_object_type(obj) == PROP_TYPE_STRING) {
printf("Filename: %s", prop_string_cstring_nocopy(obj));
obj = prop_dictionary_get(dict, "filename-size");
if (prop_object_type(obj) == PROP_TYPE_NUMBER) {
rv = xbps_humanize_number(size, 5,
(int64_t)prop_number_unsigned_integer_value(obj),
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE);
rv = xbps_humanize_number(size,
(int64_t)prop_number_unsigned_integer_value(obj));
if (rv == -1)
printf(" (size: %ju)\n",
prop_number_unsigned_integer_value(obj));
@@ -69,8 +68,7 @@ show_pkg_info(prop_dictionary_t dict)
{
prop_object_t obj;
const char *sep;
char size[64];
int rv = 0;
char size[8];
assert(dict != NULL);
assert(prop_dictionary_count(dict) != 0);
@@ -87,10 +85,8 @@ show_pkg_info(prop_dictionary_t dict)
obj = prop_dictionary_get(dict, "installed_size");
if (prop_object_type(obj) == PROP_TYPE_NUMBER) {
printf("Installed size: ");
rv = xbps_humanize_number(size, 5,
(int64_t)prop_number_unsigned_integer_value(obj),
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE);
if (rv == -1)
if (xbps_humanize_number(size,
(int64_t)prop_number_unsigned_integer_value(obj)) == -1)
printf("%ju\n",
prop_number_unsigned_integer_value(obj));
else