diff options
author | Agney Lopes Roth Ferraz <agney@debian.org> | 2006-06-21 22:18:24 -0300 |
---|---|---|
committer | Simon Quigley <tsimonq2@ubuntu.com> | 2017-06-19 14:38:36 -0500 |
commit | 078e9c700feccfcf1318b7bde49d6e464bc2ac8c (patch) | |
tree | 4d24c99643f10e4b8b75bebaaec5d48294b3b112 /util.c | |
parent | 18820242e374421ebd6d504a20d11f310b2ac023 (diff) | |
parent | 720f5023a8f68aaaa54cb6b7bf46efee23b5b4c3 (diff) |
Import Debian changes 0.4.1-1
hardinfo (0.4.1-1) unstable; urgency=low
* New upstream release.
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 35 |
1 files changed, 25 insertions, 10 deletions
@@ -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'); |