Rob Landley | 15bdc11 | 2006-11-01 22:28:46 -0500 | [diff] [blame^] | 1 | /* vi: set sw=4 ts=4 : |
| 2 | * llist.c - Linked list functions |
| 3 | * |
| 4 | * Linked list structures have a next pointer as their first element. |
| 5 | */ |
| 6 | |
| 7 | #include "toys.h" |
| 8 | |
| 9 | // Free all the elements of a linked list |
| 10 | // if freeit!=NULL call freeit() on each element before freeing it. |
| 11 | |
| 12 | void llist_free(void *list, void (*freeit)(void *data)) |
| 13 | { |
| 14 | while (list) { |
| 15 | void **next = (void **)list; |
| 16 | void *list_next = *next; |
| 17 | if (freeit) freeit(list); |
| 18 | free(list); |
| 19 | list = list_next; |
| 20 | } |
| 21 | } |