From 3dfddc18a53601463da49451c05cc62869773e16 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 25 May 2017 14:53:03 +0200 Subject: [PATCH] ifcfg-rh: add svFindFirstKeyWithPrefix() function During backporting manually patched to use GList instead of CList. (cherry picked from commit e9d960740af008acb91074b31a570fba17dc0344) --- src/settings/plugins/ifcfg-rh/shvar.c | 22 ++++++++++++++++++++++ src/settings/plugins/ifcfg-rh/shvar.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 9fce5aa117..47ad5a23f1 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -905,6 +905,28 @@ svGetKeys (shvarFile *s) /*****************************************************************************/ +const char * +svFindFirstKeyWithPrefix (shvarFile *s, const char *key_prefix) +{ + const GList *current; + const shvarLine *l; + + g_return_val_if_fail (s, NULL); + g_return_val_if_fail (key_prefix, NULL); + + for (current = s->lineList; current; current = current->next) { + l = current->data; + if ( l->key + && l->line + && g_str_has_prefix (l->key, key_prefix)) + return l->key; + } + + return NULL; +} + +/*****************************************************************************/ + static const char * _svGetValue (shvarFile *s, const char *key, char **to_free) { diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 9d8c2364a3..a13920a18c 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -44,6 +44,8 @@ shvarFile *svCreateFile (const char *name); /* Open the file , return shvarFile on success, NULL on failure */ shvarFile *svOpenFile (const char *name, GError **error); +const char *svFindFirstKeyWithPrefix (shvarFile *s, const char *key_prefix); + /* Get the value associated with the key, and leave the current pointer * pointing at the line containing the value. The char* returned MUST * be freed by the caller.