1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-11 20:58:50 +03:00

Fix display alignment of zero.

This commit is contained in:
Alasdair Kergon 2002-12-05 22:42:31 +00:00
parent 457a47f19f
commit 28879d4174

View File

@ -101,11 +101,12 @@ char *display_size(uint64_t size, size_len_t sl)
ulong byte = 1024 * 1024 * 1024; ulong byte = 1024 * 1024 * 1024;
char *size_buf = NULL; char *size_buf = NULL;
char *size_str[][2] = { char *size_str[][2] = {
{"Terabyte", "TB"}, {" Terabyte", "TB"},
{"Gigabyte", "GB"}, {" Gigabyte", "GB"},
{"Megabyte", "MB"}, {" Megabyte", "MB"},
{"Kilobyte", "KB"}, {" Kilobyte", "KB"},
{"", ""} {"", ""},
{" ", " "}
}; };
if (!(size_buf = dbg_malloc(SIZE_BUF))) { if (!(size_buf = dbg_malloc(SIZE_BUF))) {
@ -114,13 +115,13 @@ char *display_size(uint64_t size, size_len_t sl)
} }
if (size == 0LL) if (size == 0LL)
sprintf(size_buf, "0"); sprintf(size_buf, "0%s", size_str[5][sl]);
else { else {
s = 0; s = 0;
while (size_str[s] && size < byte) while (size_str[s] && size < byte)
s++, byte /= 1024; s++, byte /= 1024;
snprintf(size_buf, SIZE_BUF - 1, snprintf(size_buf, SIZE_BUF - 1,
"%.2f %s", (float) size / byte, size_str[s][sl]); "%.2f%s", (float) size / byte, size_str[s][sl]);
} }
/* Caller to deallocate */ /* Caller to deallocate */