11 const double KB = 1024.0;
12 const double MB = KB * 1024.0;
13 const double GB = MB * 1024.0;
14 const double TB = GB * 1024.0;
16 if ((
double)bytes < KB) {
17 SAFE_IGNORE_PRINTF_RESULT(
safe_snprintf(out, out_capacity,
"%zu B", bytes));
18 }
else if ((
double)bytes < MB) {
19 double value = (double)bytes / KB;
20 SAFE_IGNORE_PRINTF_RESULT(
safe_snprintf(out, out_capacity,
"%.2f KB", value));
21 }
else if ((
double)bytes < GB) {
22 double value = (double)bytes / MB;
23 SAFE_IGNORE_PRINTF_RESULT(
safe_snprintf(out, out_capacity,
"%.2f MB", value));
24 }
else if ((
double)bytes < TB) {
25 double value = (double)bytes / GB;
26 SAFE_IGNORE_PRINTF_RESULT(
safe_snprintf(out, out_capacity,
"%.2f GB", value));
28 double value = (double)bytes / TB;
29 SAFE_IGNORE_PRINTF_RESULT(
safe_snprintf(out, out_capacity,
"%.2f TB", value));
int safe_snprintf(char *buffer, size_t buffer_size, const char *format,...)
Safe formatted string printing to buffer.