diff options
author | Martin Szulecki | 2014-10-22 21:28:04 +0200 |
---|---|---|
committer | Martin Szulecki | 2014-10-22 22:21:06 +0200 |
commit | 2f32ff99f90689b364b86d4c12f3a1b8b318991e (patch) | |
tree | 16df4749e950bce8fd57a88997af342f6e81bddc /common/utils.c | |
parent | 57538472cb86d6b376f933e9e416eb769f7c00b7 (diff) | |
download | libimobiledevice-2f32ff99f90689b364b86d4c12f3a1b8b318991e.tar.gz libimobiledevice-2f32ff99f90689b364b86d4c12f3a1b8b318991e.tar.bz2 |
common: Move size format helper to utils and use it in idevicebackup tools
Diffstat (limited to 'common/utils.c')
-rw-r--r-- | common/utils.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/common/utils.c b/common/utils.c index f95ecfd..4a45d95 100644 --- a/common/utils.c +++ b/common/utils.c @@ -139,6 +139,28 @@ char *string_build_path(const char *elem, ...) return out; } +char *string_format_size(uint64_t size) +{ + char buf[80]; + double sz; + if (size >= 1000000000000LL) { + sz = ((double)size / 1000000000000.0f); + sprintf(buf, "%0.1f TB", sz); + } else if (size >= 1000000000LL) { + sz = ((double)size / 1000000000.0f); + sprintf(buf, "%0.1f GB", sz); + } else if (size >= 1000000LL) { + sz = ((double)size / 1000000.0f); + sprintf(buf, "%0.1f MB", sz); + } else if (size >= 1000LL) { + sz = ((double)size / 1000.0f); + sprintf(buf, "%0.1f KB", sz); + } else { + sprintf(buf, "%d Bytes", (int)size); + } + return strdup(buf); +} + char *string_toupper(char* str) { char *res = strdup(str); |