diff options
author | Thomas Haller <thaller@redhat.com> | 2015-06-15 12:30:44 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-07-02 15:50:03 +0200 |
commit | bb4ae800a1293aea047c113352cc5e87178bb0b2 (patch) | |
tree | 84a069828853715d4a5d90b3c4e366e3e648cfa7 | |
parent | a05e80913e6b21b38cc1e729de92bc2e1260574e (diff) | |
download | NetworkManager-bb4ae800a1293aea047c113352cc5e87178bb0b2.tar.gz |
config: add nm_config_keyfile_set_string_list() utils function
-rw-r--r-- | src/nm-config.c | 33 | ||||
-rw-r--r-- | src/nm-config.h | 5 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/nm-config.c b/src/nm-config.c index e671ca14fe..509ea992d7 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -141,6 +141,39 @@ nm_config_keyfile_get_boolean (GKeyFile *keyfile, return value; } +void +nm_config_keyfile_set_string_list (GKeyFile *keyfile, + const char *group, + const char *key, + const char *const* strv, + gssize len) +{ + gsize l; + char *new_value; + + if (len < 0) + len = strv ? g_strv_length ((char **) strv) : 0; + + g_key_file_set_string_list (keyfile, group, key, strv, len); + + /* g_key_file_set_string_list() appends a trailing separator to the value. + * We don't like that, get rid of it. */ + + new_value = g_key_file_get_value (keyfile, group, key, NULL); + if (!new_value) + return; + + l = strlen (new_value); + if (l > 0 && new_value[l - 1] == NM_CONFIG_KEYFILE_LIST_SEPARATOR) { + /* Maybe we should check that value doesn't end with "\\,", i.e. + * with an escaped separator. But the way g_key_file_set_string_list() + * is implemented (currently), it always adds a trailing separator. */ + new_value[l - 1] = '\0'; + g_key_file_set_value (keyfile, group, key, new_value); + } + g_free (new_value); +} + /************************************************************************/ NMConfigData * diff --git a/src/nm-config.h b/src/nm-config.h index 4cba2fd88f..8a08e0bb36 100644 --- a/src/nm-config.h +++ b/src/nm-config.h @@ -96,6 +96,11 @@ gboolean nm_config_keyfile_get_boolean (GKeyFile *keyfile, const char *section, const char *key, gboolean default_value); +void nm_config_keyfile_set_string_list (GKeyFile *keyfile, + const char *group, + const char *key, + const char *const* strv, + gssize len); GSList *nm_config_get_device_match_spec (const GKeyFile *keyfile, const char *group, const char *key); G_END_DECLS |