From c115fdbc800d7573d61db98c4697ed12078e7684 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Tue, 6 Mar 2007 22:53:10 +0000 Subject: ifupdown: code to deconstruct the state_list gracefully (patch by Gabriel L. Somlo ) --- libbb/llist.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'libbb') diff --git a/libbb/llist.c b/libbb/llist.c index 0a5978a..2b34f76 100644 --- a/libbb/llist.c +++ b/libbb/llist.c @@ -45,21 +45,40 @@ void llist_add_to_end(llist_t ** list_head, void *data) /* Remove first element from the list and return it */ void *llist_pop(llist_t ** head) { - void *data; + void *data, *next; if (!*head) - data = *head; - else { - void *next = (*head)->link; + return NULL; - data = (*head)->data; - free(*head); - *head = next; - } + data = (*head)->data; + next = (*head)->link; + free(*head); + *head = next; return data; } +/* Unlink arbitrary given element from the list */ +void llist_unlink(llist_t **head, llist_t *elm) +{ + llist_t *crt; + + if (!(elm && *head)) + return; + + if (elm == *head) { + *head = (*head)->link; + return; + } + + for (crt = *head; crt; crt = crt->link) { + if (crt->link == elm) { + crt->link = elm->link; + return; + } + } +} + /* Recursively free all elements in the linked list. If freeit != NULL * call it on each datum in the list */ void llist_free(llist_t * elm, void (*freeit) (void *data)) -- cgit v1.1