aboutsummaryrefslogtreecommitdiff
path: root/lib/llist.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-11-01 22:28:46 -0500
committerRob Landley <rob@landley.net>2006-11-01 22:28:46 -0500
commit15bdc11ec8dd724cc07502d534a04084d226f132 (patch)
treeb25e14744584a0e607f26e85c591e8bd20515b35 /lib/llist.c
parent401ae8fe28d8f2da0f3dee5f26cd25e6e235f4b5 (diff)
downloadtoybox-15bdc11ec8dd724cc07502d534a04084d226f132.tar.gz
Linked list functions, forgot to add this to the repository.
Diffstat (limited to 'lib/llist.c')
-rw-r--r--lib/llist.c21
1 files changed, 21 insertions, 0 deletions
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;
+ }
+}