ifcfg-rh: add svGetValueFull() function

This commit is contained in:
Thomas Haller 2015-05-20 13:41:31 +02:00
parent 32871deecc
commit 33aaa730c5
2 changed files with 18 additions and 6 deletions

View file

@ -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 <key> resolves to any truth value (e.g. "yes", "y", "true")

View file

@ -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 <key> resolves to any truth value (e.g. "yes", "y", "true")
* return FALSE if <key> resolves to any non-truth value (e.g. "no", "n", "false")