changeset 15:2a56fdc40035

Linked list functions, forgot to add this to the repository.
author Rob Landley <rob@landley.net>
date Wed, 01 Nov 2006 22:28:46 -0500
parents f8e628f61f16
children dd10785b6532
files lib/llist.c
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/llist.c	Wed Nov 01 22:28:46 2006 -0500
@@ -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;
+	}
+}