diff 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
line wrap: on
line diff
--- a/lib/llist.c	Thu Nov 02 19:50:02 2006 -0500
+++ b/lib/llist.c	Fri Nov 03 00:05:52 2006 -0500
@@ -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;
+}