]>
git.saurik.com Git - apple/system_cmds.git/blob - CPPUtil/UtilPrettyPrinting.cpp
2 // UtilPrettyPrinting.cpp
5 // Created by James McIlree on 9/8/13.
6 // Copyright (c) 2013 Apple. All rights reserved.
13 std::string
formated_byte_size(uint64_t bytes
) {
16 const char *si_prefix
[] = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
17 const int base
= 1024;
18 int c
= std::min((int)(log((double)bytes
)/log((double)base
)), (int)sizeof(si_prefix
) - 1);
19 snprintf(tmp
, sizeof(tmp
), "%1.2f %s", bytes
/ pow((double)base
, c
), si_prefix
[c
]);
20 return std::string(tmp
);
23 return std::string("0.00 B");