comparison lib/llist.c @ 20:3981c96f9285

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.
author Rob Landley <rob@landley.net>
date Fri, 03 Nov 2006 00:05:52 -0500
parents 2a56fdc40035
children 630b2e12db16
comparison
equal deleted inserted replaced
19:414625f97667 20:3981c96f9285
10 // if freeit!=NULL call freeit() on each element before freeing it. 10 // if freeit!=NULL call freeit() on each element before freeing it.
11 11
12 void llist_free(void *list, void (*freeit)(void *data)) 12 void llist_free(void *list, void (*freeit)(void *data))
13 { 13 {
14 while (list) { 14 while (list) {
15 void **next = (void **)list; 15 void *pop = llist_pop(&list);
16 void *list_next = *next; 16 if (freeit) freeit(pop);
17 if (freeit) freeit(list);
18 free(list);
19 list = list_next;
20 } 17 }
21 } 18 }
19
20 // Return the first item from the list, advancing the list (which must be called
21 // as &list)
22 void *llist_pop(void *list)
23 {
24 // I'd use a void ** for the argument, and even accept the typecast in all
25 // callers as documentation you need the &, except the stupid compiler
26 // would then scream about type-punned pointers. Screw it.
27 void **llist = (void **)list;
28 void **next = (void **)*llist;
29 *llist = *next;
30
31 return (void *)next;
32 }