diff options
author | Denis Vlasenko | 2007-03-06 22:53:10 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-03-06 22:53:10 +0000 |
commit | c115fdbc800d7573d61db98c4697ed12078e7684 (patch) | |
tree | 7d389439583b48b42692f10b121ffd4e7b24aa76 /libbb | |
parent | 9431e564aa5a595613929d4b1df82d811701febc (diff) | |
download | busybox-c115fdbc800d7573d61db98c4697ed12078e7684.zip busybox-c115fdbc800d7573d61db98c4697ed12078e7684.tar.gz |
ifupdown: code to deconstruct the state_list gracefully
(patch by Gabriel L. Somlo <somlo@cmu.edu>)
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/llist.c | 35 |
1 files changed, 27 insertions, 8 deletions
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)) |