aboutsummaryrefslogtreecommitdiff
path: root/lib/llist.c
blob: 9047e8b5bc75b0dababad2967236cffa5c5dad43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* vi: set sw=4 ts=4 :
 * llist.c - Linked list functions
 *
 * Linked list structures have a next pointer as their first element.
 */

#include "toys.h"

// Free all the elements of a linked list
// if freeit!=NULL call freeit() on each element before freeing it.

void llist_free(void *list, void (*freeit)(void *data))
{
	while (list) {
		void **next = (void **)list;
		void *list_next = *next;
		if (freeit) freeit(list);
		free(list);
		list = list_next;
	}
}