1 /* Copyright (c) 2007-2009, UNINETT AS */
2 /* See LICENSE for licensing information. */
8 /* allocates and initialises list structure; returns NULL if malloc fails */
9 struct list *list_create() {
10 struct list *list = malloc(sizeof(struct list));
12 memset(list, 0, sizeof(struct list));
16 /* frees all memory associated with the list */
17 void list_destroy(struct list *list) {
18 struct list_node *node, *next;
23 for (node = list->first; node; node = next) {
31 /* appends entry to list; returns 1 if ok, 0 if malloc fails */
32 int list_push(struct list *list, void *data) {
33 struct list_node *node;
35 node = malloc(sizeof(struct list_node));
43 list->last->next = node;
52 /* removes first entry from list and returns data */
53 void *list_shift(struct list *list) {
54 struct list_node *node;
57 if (!list || !list->first)
61 list->first = node->next;
70 /* removes all entries with matching data pointer */
71 void list_removedata(struct list *list, void *data) {
72 struct list_node *node, *t;
74 if (!list || !list->first)
78 while (node->data == data) {
79 list->first = node->next;
88 for (; node->next; node = node->next)
89 if (node->next->data == data) {
94 if (!node->next) { /* we removed the last one */
101 /* returns first node */
102 struct list_node *list_first(struct list *list) {
103 return list ? list->first : NULL;
106 /* returns the next node after the argument */
107 struct list_node *list_next(struct list_node *node) {
111 /* returns number of nodes */
112 uint32_t list_count(struct list *list) {
116 /* Local Variables: */
117 /* c-file-style: "stroustrup" */