summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-07-09 18:28:26 +0200
committerGravatar Jonathan Beck2009-07-09 18:28:26 +0200
commit365e1199ee8d42b3ee66b098f883b08bb172d51f (patch)
treedecef46e9d5dee206b081cd4cf45cfd6c5482891
parent192f335086e55e5e550557e630c5b9de461570d0 (diff)
downloadlibplist-365e1199ee8d42b3ee66b098f883b08bb172d51f.tar.gz
libplist-365e1199ee8d42b3ee66b098f883b08bb172d51f.tar.bz2
Make copy_plist actually copy plists (previously always returning NULL).
-rw-r--r--src/plist.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/plist.c b/src/plist.c
index cd563aa..c205d46 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -139,7 +139,7 @@ void plist_free(plist_t plist)
g_node_destroy(plist);
}
-static void plist_copy_node(GNode * node, gpointer parent_node)
+static void plist_copy_node(GNode * node, gpointer parent_node_ptr)
{
plist_t newnode = NULL;
plist_data_t data = plist_get_data(node);
@@ -150,15 +150,21 @@ static void plist_copy_node(GNode * node, gpointer parent_node)
memcpy(newdata, data, sizeof(struct plist_data_s));
newnode = plist_new_node(newdata);
- if (parent_node) {
- g_node_append(parent_node, newnode);
+ if (*(plist_t*)parent_node_ptr) {
+ g_node_append(*(plist_t*)parent_node_ptr, newnode);
}
- g_node_children_foreach(node, G_TRAVERSE_ALL, plist_copy_node, newnode);
+ else {
+ *(plist_t*)parent_node_ptr = newnode;
+ }
+
+ g_node_children_foreach(node, G_TRAVERSE_ALL, plist_copy_node, &newnode);
}
plist_t plist_copy(plist_t node)
{
- plist_copy_node(node, NULL);
+ plist_t copied = NULL;
+ plist_copy_node(node, &copied);
+ return copied;
}
plist_t plist_get_first_child(plist_t node)