ifcfg-rh: avoid creating temporary string prefix for svGetValueFull()

This commit is contained in:
Thomas Haller
2016-05-24 15:57:16 +02:00
parent 487dcf7e55
commit d7b4733d3e

View File

@@ -271,26 +271,23 @@ svGetValueFull (shvarFile *s, const char *key, gboolean verbatim)
{ {
char *value = NULL; char *value = NULL;
char *line; char *line;
char *keyString; guint len;
int len;
g_return_val_if_fail (s != NULL, NULL); g_return_val_if_fail (s != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL); g_return_val_if_fail (key != NULL, NULL);
keyString = g_strdup_printf ("%s=", key); len = strlen (key);
len = strlen (keyString);
for (s->current = s->lineList; s->current; s->current = s->current->next) { for (s->current = s->lineList; s->current; s->current = s->current->next) {
line = s->current->data; line = s->current->data;
if (!strncmp (keyString, line, len)) { if (!strncmp (key, line, len) && line[len] == '=') {
/* Strip trailing spaces before unescaping to preserve spaces quoted whitespace */ /* Strip trailing spaces before unescaping to preserve spaces quoted whitespace */
value = g_strchomp (g_strdup (line + len)); value = g_strchomp (g_strdup (line + len + 1));
if (!verbatim) if (!verbatim)
svUnescape (value); svUnescape (value);
break; break;
} }
} }
g_free (keyString);
return value; return value;
} }