From 720f5023a8f68aaaa54cb6b7bf46efee23b5b4c3 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Mon, 19 Jun 2017 14:38:35 -0500 Subject: Import Upstream version 0.4.1 --- util.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 79084c2c..ee6040b2 100644 --- a/util.c +++ b/util.c @@ -19,18 +19,21 @@ #include #include -inline void -remove_quotes(gchar *str) -{ - if (!str) - return; +#define KiB 1024 +#define MiB 1048576 +#define GiB 1073741824 - while (*str == '"') - *(str++) = ' '; +inline gchar * +size_human_readable(gfloat size) +{ + if (size < KiB) + return g_strdup_printf("%.1f B", size); + if (size < MiB) + return g_strdup_printf("%.1f KiB", size / KiB); + if (size < GiB) + return g_strdup_printf("%.1f MiB", size / MiB); - gchar *p; - if ((p = strchr(str, '"'))) - *p = 0; + return g_strdup_printf("%.1f GiB", size / GiB); } inline void @@ -44,6 +47,18 @@ strend(gchar *str, gchar chr) *p = 0; } +inline void +remove_quotes(gchar *str) +{ + if (!str) + return; + + while (*str == '"') + *(str++) = ' '; + + strend(str, '"'); +} + inline void remove_linefeed(gchar * str) { -- cgit v1.2.3