diff options
-rw-r--r-- | libopkg/active_list.c | 15 | ||||
-rw-r--r-- | tests/opkg_active_list_test.c | 3 |
2 files changed, 17 insertions, 1 deletions
diff --git a/libopkg/active_list.c b/libopkg/active_list.c index e297cfc..8544440 100644 --- a/libopkg/active_list.c +++ b/libopkg/active_list.c @@ -71,7 +71,22 @@ struct active_list * active_list_prev(struct active_list *head, struct active_li return prev; } +static void list_head_clear (struct list_head *head) { + struct active_list *next; + struct list_head *n, *ptr; + if (!head) + return; + list_for_each_safe(ptr, n , head) { + next = list_entry(ptr, struct active_list, node); + if (next->depend.next != &next->depend) { + list_head_clear(&next->depend); + } + list_del_init(&next->node); + next->depended = NULL; + } +} void active_list_clear(struct active_list *head) { + list_head_clear(&head->node); } void active_list_add_depend(struct active_list *node, struct active_list *depend) { diff --git a/tests/opkg_active_list_test.c b/tests/opkg_active_list_test.c index 1e21645..77819b0 100644 --- a/tests/opkg_active_list_test.c +++ b/tests/opkg_active_list_test.c @@ -111,7 +111,8 @@ int main (void) { test = list_entry(ptr, struct active_test, list); printf ("%s ",test->str); } - printf("\npos order: "); + printf("\nafter clear: "); + active_list_clear(&head); for(ptr = active_list_next(&head, NULL); ptr ;ptr = active_list_next(&head, ptr)) { test = list_entry(ptr, struct active_test, list); printf ("%s ",test->str); |