aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-05-21 06:57:43 -0500
committerRob Landley <rob@landley.net>2014-05-21 06:57:43 -0500
commite604d5344466df8584c48c8492397fcffa63a671 (patch)
tree1b351501cdee96cb897d884d5d2dff5a308ee225 /lib
parent95d2ce84789011970e2f814b2fb6c819084bde8c (diff)
downloadtoybox-e604d5344466df8584c48c8492397fcffa63a671.tar.gz
Add free functions for predefined llist types.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.h4
-rw-r--r--lib/llist.c20
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/lib.h b/lib/lib.h
index 715e78d9..f8fcd8fe 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -24,7 +24,9 @@ struct double_list {
char *data;
};
-void llist_traverse(void *list, void (*using)(void *data));
+void llist_free_arg(void *node);
+void llist_free_double(void *node);
+void llist_traverse(void *list, void (*using)(void *node));
void *llist_pop(void *list); // actually void **list
void *dlist_pop(void *list); // actually struct double_list **list
void dlist_add_nomalloc(struct double_list **list, struct double_list *new);
diff --git a/lib/llist.c b/lib/llist.c
index 71a187db..2d5bc97a 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -5,8 +5,26 @@
#include "toys.h"
+// Callback function to free data pointer of double_list or arg_list
+
+void llist_free_arg(void *node)
+{
+ struct arg_list *d = node;
+
+ free(d->arg);
+ free(d);
+}
+
+void llist_free_double(void *node)
+{
+ struct double_list *d = node;
+
+ free(d->data);
+ free(d);
+}
+
// Call a function (such as free()) on each element of a linked list.
-void llist_traverse(void *list, void (*using)(void *data))
+void llist_traverse(void *list, void (*using)(void *node))
{
void *old = list;