Commit 6697e492 authored by Nikias Bassen's avatar Nikias Bassen

libcnary: return removed/detached index in node_list_remove/node_detach

parent 7060250b
......@@ -95,11 +95,12 @@ int node_attach(node_t* parent, node_t* child) {
}
int node_detach(node_t* parent, node_t* child) {
if (!parent || !child) return 0;
if (node_list_remove(parent->children, child) == 0) {
if (!parent || !child) return -1;
int index = node_list_remove(parent->children, child);
if (index >= 0) {
parent->count--;
}
return 0;
return index;
}
int node_insert(node_t* parent, unsigned int index, node_t* child)
......
......@@ -124,6 +124,7 @@ int node_list_remove(node_list_t* list, node_t* node) {
if (!list || !node) return -1;
if (list->count == 0) return -1;
int index = 0;
node_t* n;
for (n = list->begin; n; n = n->next) {
if (node == n) {
......@@ -144,8 +145,9 @@ int node_list_remove(node_list_t* list, node_t* node) {
list->begin = newnode;
}
list->count--;
return 0;
return index;
}
index++;
}
return -1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment