From 7b3c726991f0f060ca18c576fc7816b930435240 Mon Sep 17 00:00:00 2001 From: "Leandro A. F. Pereira" Date: Sat, 20 May 2006 14:41:28 +0000 Subject: - Add binreloc support. - Add users information. - Add ppc64 and mips64 support. - Fix loadgraph autoscaling (should be usable now! :) - Misc cosmetic changes. - Misc wording changes. --- hardinfo2/util.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'hardinfo2/util.c') diff --git a/hardinfo2/util.c b/hardinfo2/util.c index 79084c2c..ee6040b2 100644 --- a/hardinfo2/util.c +++ b/hardinfo2/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