Split uc_human_bytesz in uc_human_bytesz_dec/uc_human_bytesz_bin, for
decimal and binary conversion (http://en.wikipedia.org/wiki/Megabyte)
This commit is contained in:
+20
-1
@@ -3,7 +3,7 @@
|
||||
#include "ucore/string.h"
|
||||
|
||||
char *
|
||||
uc_human_bytesz(uint64_t bytes, char *result, size_t result_len)
|
||||
uc_human_bytesz_dec(uint64_t bytes, char *result, size_t result_len)
|
||||
{
|
||||
if (bytes < 1000) {
|
||||
snprintf(result, result_len, "%" PRIu64 " b", bytes);
|
||||
@@ -22,3 +22,22 @@ uc_human_bytesz(uint64_t bytes, char *result, size_t result_len)
|
||||
return result;
|
||||
}
|
||||
|
||||
char *
|
||||
uc_human_bytesz_bin(uint64_t bytes, char *result, size_t result_len)
|
||||
{
|
||||
if (bytes < 1024) {
|
||||
snprintf(result, result_len, "%" PRIu64 " b", bytes);
|
||||
} else if (bytes < 1048576) {
|
||||
snprintf(result, result_len, "%.2f KiB", bytes/1024.0);
|
||||
} else if (bytes < 1073741824ULL) {
|
||||
snprintf(result, result_len, "%.2f MiB", bytes/1048576.0);
|
||||
} else if (bytes < 1099511627776ULL) {
|
||||
snprintf(result, result_len, "%.2f GiB", bytes/1073741824.0);
|
||||
} else if (bytes < 1125899906842624ULL) {
|
||||
snprintf(result, result_len, "%.2f TiB", bytes/1099511627776.0);
|
||||
} else {
|
||||
snprintf(result, result_len, "%.2f PiB", bytes/1125899906842624.0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user