5 /* allocates and initialises list structure; returns NULL if malloc fails */
6 struct list *list_create() {
7 struct list *list = malloc(sizeof(struct list));
9 memset(list, 0, sizeof(struct list));
13 /* frees all memory associated with the list */
14 void list_destroy(struct list *list) {
15 struct list_node *node, *next;
17 for (node = list->first; node; node = next) {
25 /* appends entry to list; returns 1 if ok, 0 if malloc fails */
26 int list_push(struct list *list, void *data) {
27 struct list_node *node;
29 node = malloc(sizeof(struct list_node));
37 list->last->next = node;
45 /* removes first entry from list and returns data */
46 void *list_shift(struct list *list) {
47 struct list_node *node;
54 list->first = node->next;
63 /* removes first entry with matching data pointer */
64 void list_removedata(struct list *list, void *data) {
65 struct list_node *node, *t;
71 if (node->data == data) {
72 list->first = node->next;
78 for (; node->next; node = node->next)
79 if (node->next->data == data) {
81 node->next = node->next->next;
82 if (!node->next) /* we removed the last one */
89 /* returns first node */
90 struct list_node *list_first(struct list *list) {
91 return list ? list->first : NULL;
94 /* returns the next node after the argument */
95 struct list_node *list_next(struct list_node *node) {