summaryrefslogtreecommitdiffstats
path: root/libcnary
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2012-04-24 01:10:46 +0200
committerGravatar Nikias Bassen2012-04-24 01:10:46 +0200
commit6697e4927883843e1bd537d778fc58bebd9a0b4e (patch)
tree833289631dc5f4db12399b0e32f623d757957800 /libcnary
parent7060250b7583ad9cd20007b6fda5dcf068d55cbe (diff)
downloadlibplist-6697e4927883843e1bd537d778fc58bebd9a0b4e.tar.gz
libplist-6697e4927883843e1bd537d778fc58bebd9a0b4e.tar.bz2
libcnary: return removed/detached index in node_list_remove/node_detach
Diffstat (limited to 'libcnary')
-rw-r--r--libcnary/node.c7
-rw-r--r--libcnary/node_list.c4
2 files changed, 7 insertions, 4 deletions
diff --git a/libcnary/node.c b/libcnary/node.c
index 264c78e..0a8f414 100644
--- a/libcnary/node.c
+++ b/libcnary/node.c
@@ -95,11 +95,12 @@ int node_attach(node_t* parent, node_t* child) {
95} 95}
96 96
97int node_detach(node_t* parent, node_t* child) { 97int node_detach(node_t* parent, node_t* child) {
98 if (!parent || !child) return 0; 98 if (!parent || !child) return -1;
99 if (node_list_remove(parent->children, child) == 0) { 99 int index = node_list_remove(parent->children, child);
100 if (index >= 0) {
100 parent->count--; 101 parent->count--;
101 } 102 }
102 return 0; 103 return index;
103} 104}
104 105
105int node_insert(node_t* parent, unsigned int index, node_t* child) 106int node_insert(node_t* parent, unsigned int index, node_t* child)
diff --git a/libcnary/node_list.c b/libcnary/node_list.c
index 78f450e..5b291e7 100644
--- a/libcnary/node_list.c
+++ b/libcnary/node_list.c
@@ -124,6 +124,7 @@ int node_list_remove(node_list_t* list, node_t* node) {
124 if (!list || !node) return -1; 124 if (!list || !node) return -1;
125 if (list->count == 0) return -1; 125 if (list->count == 0) return -1;
126 126
127 int index = 0;
127 node_t* n; 128 node_t* n;
128 for (n = list->begin; n; n = n->next) { 129 for (n = list->begin; n; n = n->next) {
129 if (node == n) { 130 if (node == n) {
@@ -144,8 +145,9 @@ int node_list_remove(node_list_t* list, node_t* node) {
144 list->begin = newnode; 145 list->begin = newnode;
145 } 146 }
146 list->count--; 147 list->count--;
147 return 0; 148 return index;
148 } 149 }
150 index++;
149 } 151 }
150 return -1; 152 return -1;
151} 153}