2 * Copyright (C) 2006-2009 Stig Venaas <venaas@uninett.no>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
9 #if defined HAVE_CONFIG_H
17 /* allocates and initialises list structure; returns NULL if malloc fails */
18 struct list *list_create() {
19 struct list *list = malloc(sizeof(struct list));
21 memset(list, 0, sizeof(struct list));
25 /* frees all memory associated with the list */
26 void list_destroy(struct list *list) {
27 struct list_node *node, *next;
32 for (node = list->first; node; node = next) {
40 /* appends entry to list; returns 1 if ok, 0 if malloc fails */
41 int list_push(struct list *list, void *data) {
42 struct list_node *node;
44 node = malloc(sizeof(struct list_node));
52 list->last->next = node;
61 /* removes first entry from list and returns data */
62 void *list_shift(struct list *list) {
63 struct list_node *node;
66 if (!list || !list->first)
70 list->first = node->next;
79 /* removes all entries with matching data pointer */
80 void list_removedata(struct list *list, void *data) {
81 struct list_node *node, *t;
83 if (!list || !list->first)
87 while (node->data == data) {
88 list->first = node->next;
97 for (; node->next; node = node->next)
98 if (node->next->data == data) {
100 node->next = t->next;
103 if (!node->next) { /* we removed the last one */
110 /* returns first node */
111 struct list_node *list_first(struct list *list) {
112 return list ? list->first : NULL;
115 /* returns the next node after the argument */
116 struct list_node *list_next(struct list_node *node) {
120 /* returns number of nodes */
121 uint32_t list_count(struct list *list) {
125 /* Local Variables: */
126 /* c-file-style: "stroustrup" */