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 Reutner-Fischer
8 * Copyright (C) 2006 Rob Landley <rob@landley.net>
10 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
14 /* Add data to the start of the linked list. */
15 void FAST_FUNC llist_add_to(llist_t **old_head, void *data)
17 llist_t *new_head = xmalloc(sizeof(llist_t));
19 new_head->data = data;
20 new_head->link = *old_head;
24 /* Add data to the end of the linked list. */
25 void FAST_FUNC llist_add_to_end(llist_t **list_head, void *data)
28 list_head = &(*list_head)->link;
29 *list_head = xzalloc(sizeof(llist_t));
30 (*list_head)->data = data;
31 /*(*list_head)->link = NULL;*/
34 /* Remove first element from the list and return it */
35 void* FAST_FUNC llist_pop(llist_t **head)
38 llist_t *temp = *head;
48 /* Unlink arbitrary given element from the list */
49 void FAST_FUNC llist_unlink(llist_t **head, llist_t *elm)
55 *head = (*head)->link;
58 head = &(*head)->link;
62 /* Recursively free all elements in the linked list. If freeit != NULL
63 * call it on each datum in the list */
64 void FAST_FUNC llist_free(llist_t *elm, void (*freeit)(void *data))
67 void *data = llist_pop(&elm);
74 /* Reverse list order. */
75 llist_t* FAST_FUNC llist_rev(llist_t *list)
80 llist_t *next = list->link;
89 llist_t* FAST_FUNC llist_find_str(llist_t *list, const char *str)
92 if (strcmp(list->data, str) == 0)