[gnome-battery-bench] SystemInfo: properly string (session) renderer
- From: Christian Kellner <gicmo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-battery-bench] SystemInfo: properly string (session) renderer
- Date: Tue, 23 May 2017 16:27:36 +0000 (UTC)
commit 85f539ba6f729d349d7a6456ee8c83568306faeb
Author: Christian Kellner <gicmo gnome org>
Date: Fri May 12 16:24:37 2017 +0100
SystemInfo: properly string (session) renderer
Introduce two new helper functions to make cleaning strings we
get back from helpers and such easier.
src/system-info.c | 33 +++++++++++++++++++++++++++------
1 files changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/src/system-info.c b/src/system-info.c
index 30604c4..7e46820 100644
--- a/src/system-info.c
+++ b/src/system-info.c
@@ -409,6 +409,32 @@ gbb_system_info_class_init (GbbSystemInfoClass *klass)
}
static char *
+gbb_str_clean(char *input)
+{
+ char *cleaned = g_strstrip(input);
+
+ if (*cleaned == '\0') {
+ g_free(cleaned);
+ cleaned = NULL;
+ }
+
+ return cleaned;
+}
+
+static char *
+gbb_strdup_clean(const char *input)
+{
+ char *cleaned;
+
+ if (input == NULL || *input == '\0') {
+ return NULL;
+ }
+
+ cleaned = g_strdup(input);
+ return gbb_str_clean(cleaned);
+}
+
+static char *
read_sysfs_string(const char *node)
{
gboolean ok;
@@ -659,12 +685,7 @@ get_renderer_from_session (void)
}
renderer = g_variant_get_string(var, NULL);
-
- if (renderer != NULL && renderer[0] != '\0') {
- return NULL;
- }
-
- return g_strstrip(g_strdup(renderer));
+ return gbb_strdup_clean(renderer);
}
static char *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]