From 33aaa730c5b57ee406bd8e1affa29ee117209ca9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 20 May 2015 13:41:31 +0200 Subject: [PATCH] ifcfg-rh: add svGetValueFull() function --- src/settings/plugins/ifcfg-rh/shvar.c | 23 +++++++++++++++++------ src/settings/plugins/ifcfg-rh/shvar.h | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 0aa9569608..75c038ccaf 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -256,6 +256,22 @@ svEscape (const char *s, char **to_free) */ char * svGetValue (shvarFile *s, const char *key, gboolean verbatim) +{ + char *value; + + value = svGetValueFull (s, key, verbatim); + if (value && !*value) { + g_free (value); + return NULL; + } + return value; +} + +/* svGetValueFull() is identical to svGetValue() except that + * svGetValue() will never return an empty value (but %NULL instead). + * svGetValueFull() will return empty values if that is the value for the @key. */ +char * +svGetValueFull (shvarFile *s, const char *key, gboolean verbatim) { char *value = NULL; char *line; @@ -280,12 +296,7 @@ svGetValue (shvarFile *s, const char *key, gboolean verbatim) } g_free (keyString); - if (value && value[0]) { - return value; - } else { - g_free (value); - return NULL; - } + return value; } /* return TRUE if resolves to any truth value (e.g. "yes", "y", "true") diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 28634ddd5d..738bce6d11 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -56,6 +56,7 @@ shvarFile *svOpenFile (const char *name, GError **error); * be freed by the caller. */ char *svGetValue (shvarFile *s, const char *key, gboolean verbatim); +char *svGetValueFull (shvarFile *s, const char *key, gboolean verbatim); /* return TRUE if resolves to any truth value (e.g. "yes", "y", "true") * return FALSE if resolves to any non-truth value (e.g. "no", "n", "false")