aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-06 22:53:10 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-06 22:53:10 +0000
commitc115fdbc800d7573d61db98c4697ed12078e7684 (patch)
tree7d389439583b48b42692f10b121ffd4e7b24aa76 /libbb
parent9431e564aa5a595613929d4b1df82d811701febc (diff)
downloadbusybox-w32-c115fdbc800d7573d61db98c4697ed12078e7684.tar.gz
busybox-w32-c115fdbc800d7573d61db98c4697ed12078e7684.tar.bz2
busybox-w32-c115fdbc800d7573d61db98c4697ed12078e7684.zip
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.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/libbb/llist.c b/libbb/llist.c
index 0a5978a26..2b34f762c 100644
--- a/libbb/llist.c
+++ b/libbb/llist.c
@@ -45,21 +45,40 @@ void llist_add_to_end(llist_t ** list_head, void *data)
45/* Remove first element from the list and return it */ 45/* Remove first element from the list and return it */
46void *llist_pop(llist_t ** head) 46void *llist_pop(llist_t ** head)
47{ 47{
48 void *data; 48 void *data, *next;
49 49
50 if (!*head) 50 if (!*head)
51 data = *head; 51 return NULL;
52 else {
53 void *next = (*head)->link;
54 52
55 data = (*head)->data; 53 data = (*head)->data;
56 free(*head); 54 next = (*head)->link;
57 *head = next; 55 free(*head);
58 } 56 *head = next;
59 57
60 return data; 58 return data;
61} 59}
62 60
61/* Unlink arbitrary given element from the list */
62void llist_unlink(llist_t **head, llist_t *elm)
63{
64 llist_t *crt;
65
66 if (!(elm && *head))
67 return;
68
69 if (elm == *head) {
70 *head = (*head)->link;
71 return;
72 }
73
74 for (crt = *head; crt; crt = crt->link) {
75 if (crt->link == elm) {
76 crt->link = elm->link;
77 return;
78 }
79 }
80}
81
63/* Recursively free all elements in the linked list. If freeit != NULL 82/* Recursively free all elements in the linked list. If freeit != NULL
64 * call it on each datum in the list */ 83 * call it on each datum in the list */
65void llist_free(llist_t * elm, void (*freeit) (void *data)) 84void llist_free(llist_t * elm, void (*freeit) (void *data))