diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/utils.c | 22 | ||||
| -rw-r--r-- | common/utils.h | 1 |
2 files changed, 23 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, ...) | |||
| 139 | return out; | 139 | return out; |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | char *string_format_size(uint64_t size) | ||
| 143 | { | ||
| 144 | char buf[80]; | ||
| 145 | double sz; | ||
| 146 | if (size >= 1000000000000LL) { | ||
| 147 | sz = ((double)size / 1000000000000.0f); | ||
| 148 | sprintf(buf, "%0.1f TB", sz); | ||
| 149 | } else if (size >= 1000000000LL) { | ||
| 150 | sz = ((double)size / 1000000000.0f); | ||
| 151 | sprintf(buf, "%0.1f GB", sz); | ||
| 152 | } else if (size >= 1000000LL) { | ||
| 153 | sz = ((double)size / 1000000.0f); | ||
| 154 | sprintf(buf, "%0.1f MB", sz); | ||
| 155 | } else if (size >= 1000LL) { | ||
| 156 | sz = ((double)size / 1000.0f); | ||
| 157 | sprintf(buf, "%0.1f KB", sz); | ||
| 158 | } else { | ||
| 159 | sprintf(buf, "%d Bytes", (int)size); | ||
| 160 | } | ||
| 161 | return strdup(buf); | ||
| 162 | } | ||
| 163 | |||
| 142 | char *string_toupper(char* str) | 164 | char *string_toupper(char* str) |
| 143 | { | 165 | { |
| 144 | char *res = strdup(str); | 166 | char *res = strdup(str); |
diff --git a/common/utils.h b/common/utils.h index 5cd4a53..97d3748 100644 --- a/common/utils.h +++ b/common/utils.h | |||
| @@ -38,6 +38,7 @@ char *stpcpy(char *s1, const char *s2); | |||
| 38 | #endif | 38 | #endif |
| 39 | char *string_concat(const char *str, ...); | 39 | char *string_concat(const char *str, ...); |
| 40 | char *string_build_path(const char *elem, ...); | 40 | char *string_build_path(const char *elem, ...); |
| 41 | char *string_format_size(uint64_t size); | ||
| 41 | char *string_toupper(char *str); | 42 | char *string_toupper(char *str); |
| 42 | char *generate_uuid(); | 43 | char *generate_uuid(); |
| 43 | 44 | ||
