diff options
author | Rob Landley <rob@landley.net> | 2006-11-03 00:05:52 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-11-03 00:05:52 -0500 |
commit | 0a04b3ef850cd3d6f06b3c8d0036993adc9ba7b2 (patch) | |
tree | 6833c64668f917b4f03c9c5317a4313937960ba4 /lib/llist.c | |
parent | 7fc43f79783658a38be23ca8b3cdac5f11e397d1 (diff) | |
download | toybox-0a04b3ef850cd3d6f06b3c8d0036993adc9ba7b2.tar.gz |
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.
Diffstat (limited to 'lib/llist.c')
-rw-r--r-- | lib/llist.c | 21 |
1 files changed, 16 insertions, 5 deletions
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; +} |