summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 14:38:35 -0500
committerSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 14:38:35 -0500
commit720f5023a8f68aaaa54cb6b7bf46efee23b5b4c3 (patch)
tree26a8d91183787418455f65c2bb44ed641800dad3 /util.c
parent854292407779593a401a1d5ce71add51880fa84f (diff)
Import Upstream version 0.4.1
Diffstat (limited to 'util.c')
-rw-r--r--util.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/util.c b/util.c
index 79084c2c..ee6040b2 100644
--- a/util.c
+++ b/util.c
@@ -19,18 +19,21 @@
#include <hardinfo.h>
#include <gtk/gtk.h>
-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
@@ -45,6 +48,18 @@ strend(gchar *str, gchar chr)
}
inline void
+remove_quotes(gchar *str)
+{
+ if (!str)
+ return;
+
+ while (*str == '"')
+ *(str++) = ' ';
+
+ strend(str, '"');
+}
+
+inline void
remove_linefeed(gchar * str)
{
strend(str, '\n');