Linked list functions, forgot to add this to the repository.
authorRob Landley <rob@landley.net>
Thu, 2 Nov 2006 03:28:46 +0000 (22:28 -0500)
committerRob Landley <rob@landley.net>
Thu, 2 Nov 2006 03:28:46 +0000 (22:28 -0500)
lib/llist.c [new file with mode: 0644]

diff --git a/lib/llist.c b/lib/llist.c
new file mode 100644 (file)
index 0000000..9047e8b
--- /dev/null
@@ -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;
+       }
+}