From 0a04b3ef850cd3d6f06b3c8d0036993adc9ba7b2 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 3 Nov 2006 00:05:52 -0500 Subject: Implement which. Add hello world to menuconfig. Wrap the various applet main functions in main.c with USE() macros so --gc-sections can strip them. --- lib/llist.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index 9047e8b5..8d6fd265 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -12,10 +12,21 @@ 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; + void *pop = llist_pop(&list); + if (freeit) freeit(pop); } } + +// Return the first item from the list, advancing the list (which must be called +// as &list) +void *llist_pop(void *list) +{ + // I'd use a void ** for the argument, and even accept the typecast in all + // callers as documentation you need the &, except the stupid compiler + // would then scream about type-punned pointers. Screw it. + void **llist = (void **)list; + void **next = (void **)*llist; + *llist = *next; + + return (void *)next; +} -- cgit v1.2.3