1 /* llist.c - Linked list functions
3 * Linked list structures have a next pointer as their first element.
8 // Call a function (such as free()) on each element of a linked list.
9 void llist_traverse(void *list, void (*using)(void *data))
12 void *pop = llist_pop(&list);
15 // End doubly linked list too.
20 // Return the first item from the list, advancing the list (which must be called
22 void *llist_pop(void *list)
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;
34 void dlist_add_nomalloc(struct double_list **list, struct double_list *new)
38 new->prev = (*list)->prev;
39 (*list)->prev->next = new;
41 } else *list = new->next = new->prev = new;
45 // Add an entry to the end of a doubly linked list
46 struct double_list *dlist_add(struct double_list **list, char *data)
48 struct double_list *new = xmalloc(sizeof(struct double_list));
51 dlist_add_nomalloc(list, new);