summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2014-12-03 17:16:48 -0500
committerMatthew Barnes <mbarnes@redhat.com>2014-12-08 12:47:19 -0500
commitf3dcb7a052ecc94fb25a9e4598dea911e71e6221 (patch)
tree3f715f1d315447101771824299a042a63084d102
parentdbf717ac4b1ad5f4f8e221555a3a4872f2e454a1 (diff)
downloadostree-f3dcb7a052ecc94fb25a9e4598dea911e71e6221.tar.gz
libotutil: Add ot_keyfile_copy_group()
Copies all the keys of a group from one GKeyFile to another.
-rw-r--r--src/libotutil/ot-keyfile-utils.c32
-rw-r--r--src/libotutil/ot-keyfile-utils.h5
2 files changed, 37 insertions, 0 deletions
diff --git a/src/libotutil/ot-keyfile-utils.c b/src/libotutil/ot-keyfile-utils.c
index 833a76f6..6a893571 100644
--- a/src/libotutil/ot-keyfile-utils.c
+++ b/src/libotutil/ot-keyfile-utils.c
@@ -91,3 +91,35 @@ ot_keyfile_get_value_with_default (GKeyFile *keyfile,
out:
return ret;
}
+
+gboolean
+ot_keyfile_copy_group (GKeyFile *source_keyfile,
+ GKeyFile *target_keyfile,
+ const char *group_name)
+{
+ gs_strfreev char **keys = NULL;
+ gsize length, ii;
+ gboolean ret = FALSE;
+
+ g_return_if_fail (source_keyfile != NULL);
+ g_return_if_fail (target_keyfile != NULL);
+ g_return_if_fail (group_name != NULL);
+
+ keys = g_key_file_get_keys (source_keyfile, group_name, &length, NULL);
+
+ if (keys == NULL)
+ goto out;
+
+ for (ii = 0; ii < length; ii++)
+ {
+ gs_free char *value = NULL;
+
+ value = g_key_file_get_value (source_keyfile, group_name, keys[ii], NULL);
+ g_key_file_set_value (target_keyfile, group_name, keys[ii], value);
+ }
+
+ ret = TRUE;
+
+ out:
+ return ret;
+}
diff --git a/src/libotutil/ot-keyfile-utils.h b/src/libotutil/ot-keyfile-utils.h
index 057cc638..576785ac 100644
--- a/src/libotutil/ot-keyfile-utils.h
+++ b/src/libotutil/ot-keyfile-utils.h
@@ -43,5 +43,10 @@ ot_keyfile_get_value_with_default (GKeyFile *keyfile,
char **out_value,
GError **error);
+gboolean
+ot_keyfile_copy_group (GKeyFile *source_keyfile,
+ GKeyFile *target_keyfile,
+ const char *group_name);
+
G_END_DECLS