ifupdown: code to deconstruct the state_list gracefully
(patch by Gabriel L. Somlo <somlo@cmu.edu>)
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user