1 /* vi: set sw=4 ts=4: */
3 * linked list helper functions.
5 * Copyright (C) 2003 Glenn McGrath
6 * Copyright (C) 2005 Vladimir Oleynik
7 * Copyright (C) 2005 Bernhard Fischer
9 * Licensed under the GPL v2, see the file LICENSE in this tarball.
15 /* Add data to the start of the linked list. */
16 extern llist_t *llist_add_to(llist_t *old_head, char *new_item)
20 new_head = xmalloc(sizeof(llist_t));
21 new_head->data = new_item;
22 new_head->link = old_head;
28 #ifdef L_llist_add_to_end
29 /* Add data to the end of the linked list. */
30 extern llist_t *llist_add_to_end(llist_t *list_head, char *data)
34 new_item = xmalloc(sizeof(llist_t));
35 new_item->data = data;
36 new_item->link = NULL;
38 if (list_head == NULL) {
41 llist_t *tail = list_head;
44 tail->link = new_item;
50 #ifdef L_llist_free_one
51 /* Free the current list element and advance to the next entry in the list.
52 * Returns a pointer to the next element. */
53 extern llist_t *llist_free_one(llist_t *elm)
55 llist_t *next = elm ? elm->link : NULL;
56 #if ENABLE_DMALLOC /* avoid warnings from dmalloc's error-free-null option */
66 /* Recursively free all elements in the linked list. */
67 extern void llist_free(llist_t *elm)
69 while ((elm = llist_free_one(elm)));