[ostree] libotutil: Add ot_keyfile_copy_group()



commit f3dcb7a052ecc94fb25a9e4598dea911e71e6221
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Dec 3 17:16:48 2014 -0500

    libotutil: Add ot_keyfile_copy_group()
    
    Copies all the keys of a group from one GKeyFile to another.

 src/libotutil/ot-keyfile-utils.c |   32 ++++++++++++++++++++++++++++++++
 src/libotutil/ot-keyfile-utils.h |    5 +++++
 2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/src/libotutil/ot-keyfile-utils.c b/src/libotutil/ot-keyfile-utils.c
index 833a76f..6a89357 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 057cc63..576785a 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
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]