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;
20 for (node = list->first; node; node = next) {
28 /* appends entry to list; returns 1 if ok, 0 if malloc fails */
29 int list_push(struct list *list, void *data) {
30 struct list_node *node;
32 node = malloc(sizeof(struct list_node));
40 list->last->next = node;
48 /* removes first entry from list and returns data */
49 void *list_shift(struct list *list) {
50 struct list_node *node;
57 list->first = node->next;
66 /* removes all entries with matching data pointer */
67 void list_removedata(struct list *list, void *data) {
68 struct list_node *node, *t;
70 if (!list || !list->first)
74 while (node->data == data) {
75 list->first = node->next;
83 for (; node->next; node = node->next)
84 if (node->next->data == data) {
88 if (!node->next) { /* we removed the last one */
95 /* returns first node */
96 struct list_node *list_first(struct list *list) {
97 return list ? list->first : NULL;
100 /* returns the next node after the argument */
101 struct list_node *list_next(struct list_node *node) {