aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
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))