unit > 0 : size in binary bytes unit == 0: count as decimal unit < 0 : count in binary
| 133 | // unit == 0: count as decimal |
| 134 | // unit < 0 : count in binary |
| 135 | static void mi_printf_amount(int64_t n, int64_t unit, mi_output_fun* out, void* arg, const char* fmt) { |
| 136 | char buf[32]; buf[0] = 0; |
| 137 | int len = 32; |
| 138 | const char* suffix = (unit <= 0 ? " " : "B"); |
| 139 | const int64_t base = (unit == 0 ? 1000 : 1024); |
| 140 | if (unit>0) n *= unit; |
| 141 | |
| 142 | const int64_t pos = (n < 0 ? -n : n); |
| 143 | if (pos < base) { |
| 144 | if (n!=1 || suffix[0] != 'B') { // skip printing 1 B for the unit column |
| 145 | snprintf(buf, len, "%d %-3s", (int)n, (n==0 ? "" : suffix)); |
| 146 | } |
| 147 | } |
| 148 | else { |
| 149 | int64_t divider = base; |
| 150 | const char* magnitude = "K"; |
| 151 | if (pos >= divider*base) { divider *= base; magnitude = "M"; } |
| 152 | if (pos >= divider*base) { divider *= base; magnitude = "G"; } |
| 153 | const int64_t tens = (n / (divider/10)); |
| 154 | const long whole = (long)(tens/10); |
| 155 | const long frac1 = (long)(tens%10); |
| 156 | char unitdesc[8]; |
| 157 | snprintf(unitdesc, 8, "%s%s%s", magnitude, (base==1024 ? "i" : ""), suffix); |
| 158 | snprintf(buf, len, "%ld.%ld %-3s", whole, (frac1 < 0 ? -frac1 : frac1), unitdesc); |
| 159 | } |
| 160 | _mi_fprintf(out, arg, (fmt==NULL ? "%11s" : fmt), buf); |
| 161 | } |
| 162 | |
| 163 | |
| 164 | static void mi_print_amount(int64_t n, int64_t unit, mi_output_fun* out, void* arg) { |
no test coverage detected