From 15bdc11ec8dd724cc07502d534a04084d226f132 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 1 Nov 2006 22:28:46 -0500 Subject: Linked list functions, forgot to add this to the repository. --- lib/llist.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/llist.c (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c new file mode 100644 index 00000000..9047e8b5 --- /dev/null +++ b/lib/llist.c @@ -0,0 +1,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; + } +} -- cgit v1.2.3