Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
char postfix[] = { ' ', 'K', 'M', 'G', 'P', 'E' };
unsigned int thousand;
char *buf;
char postfix[] = { ' ', 'K', 'M', 'G', 'P', 'E' };
unsigned int thousand;
char *buf;
if (pow2)
thousand = 1024;
if (pow2)
thousand = 1024;
len = sprintf(buf, "%'lu", num);
if (len <= maxlen) {
if (i >= 1) {
len = sprintf(buf, "%'lu", num);
if (len <= maxlen) {
if (i >= 1) {
+ char dec[4];
+ int j = 0;
+
+ sprintf(dec, "%u", mod);
+ if (maxlen - len >= 2) {
+ buf[len++] = '.';
+ while (maxlen - len) {
+ buf[len++] = dec[j++];
+ if (j == sizeof(dec) - 1)
+ break;
+ }
+ }
+
buf[len] = postfix[i];
buf[len + 1] = '\0';
}
buf[len] = postfix[i];
buf[len + 1] = '\0';
}
if ((num % thousand) >= (thousand / 2))
carry = 1;
if ((num % thousand) >= (thousand / 2))
carry = 1;
num /= thousand;
num += carry;
i++;
num /= thousand;
num += carry;
i++;