1 /* Copyright (c) 2006-2010, UNINETT AS.
2 * Copyright (c) 2010, UNINETT AS, NORDUnet A/S.
3 * Copyright (c) 2010-2012, NORDUnet A/S. */
4 /* See LICENSE for licensing information. */
10 /* allocates and initialises list structure; returns NULL if malloc fails */
11 struct list *list_create() {
12 struct list *list = malloc(sizeof(struct list));
14 memset(list, 0, sizeof(struct list));
18 /* frees all memory associated with the list */
19 void list_destroy(struct list *list) {
20 struct list_node *node, *next;
25 for (node = list->first; node; node = next) {
33 /* appends entry to list; returns 1 if ok, 0 if malloc fails */
34 int list_push(struct list *list, void *data) {
35 struct list_node *node;
37 node = malloc(sizeof(struct list_node));
45 list->last->next = node;
54 /* removes first entry from list and returns data */
55 void *list_shift(struct list *list) {
56 struct list_node *node;
59 if (!list || !list->first)
63 list->first = node->next;
72 /* removes all entries with matching data pointer */
73 void list_removedata(struct list *list, void *data) {
74 struct list_node *node, *t;
76 if (!list || !list->first)
80 while (node->data == data) {
81 list->first = node->next;
90 for (; node->next; node = node->next)
91 if (node->next->data == data) {
96 if (!node->next) { /* we removed the last one */
103 /* returns first node */
104 struct list_node *list_first(struct list *list) {
105 return list ? list->first : NULL;
108 /* returns the next node after the argument */
109 struct list_node *list_next(struct list_node *node) {
113 /* returns number of nodes */
114 uint32_t list_count(struct list *list) {
118 /* Local Variables: */
119 /* c-file-style: "stroustrup" */