1 /* Copyright (c) 2007-2009, UNINETT AS */
2 /* See LICENSE for licensing information. */
4 #if defined HAVE_CONFIG_H
12 /* allocates and initialises list structure; returns NULL if malloc fails */
13 struct list *list_create() {
14 struct list *list = malloc(sizeof(struct list));
16 memset(list, 0, sizeof(struct list));
20 /* frees all memory associated with the list */
21 void list_destroy(struct list *list) {
22 struct list_node *node, *next;
27 for (node = list->first; node; node = next) {
35 /* appends entry to list; returns 1 if ok, 0 if malloc fails */
36 int list_push(struct list *list, void *data) {
37 struct list_node *node;
39 node = malloc(sizeof(struct list_node));
47 list->last->next = node;
56 /* removes first entry from list and returns data */
57 void *list_shift(struct list *list) {
58 struct list_node *node;
61 if (!list || !list->first)
65 list->first = node->next;
74 /* removes all entries with matching data pointer */
75 void list_removedata(struct list *list, void *data) {
76 struct list_node *node, *t;
78 if (!list || !list->first)
82 while (node->data == data) {
83 list->first = node->next;
92 for (; node->next; node = node->next)
93 if (node->next->data == data) {
98 if (!node->next) { /* we removed the last one */
105 /* returns first node */
106 struct list_node *list_first(struct list *list) {
107 return list ? list->first : NULL;
110 /* returns the next node after the argument */
111 struct list_node *list_next(struct list_node *node) {
115 /* returns number of nodes */
116 uint32_t list_count(struct list *list) {
120 /* Local Variables: */
121 /* c-file-style: "stroustrup" */