2 * Sherlock Library -- Linked Lists
4 * (c) 2003 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
10 #ifndef _SHERLOCK_LISTS_H
11 #define _SHERLOCK_LISTS_H
14 struct node *next, *prev;
21 static inline void *list_first(list *l)
23 return (l->head.next != &l->head) ? l->head.next : NULL;
26 static inline void *list_last(list *l)
28 return (l->head.prev != &l->head) ? l->head.prev : NULL;
31 #define WALK_LIST(n,list) for(n=(void*)(list).head; ((node*)(n))->next != &(list).head; n=(void*)((node*)(n))->next)
33 static inline void list_insert(node *what, node *after)
35 node *before = after->next;
37 what->prev = before->prev;
42 static inline void list_add_tail(list *l, node *n)
44 list_insert(n, l->head.prev);
47 static inline void list_add_head(list *l, node *n)
49 list_insert(n, &l->head);
52 static inline void list_remove(node *n)
54 node *before = n->prev;
55 node *after = n->next;
60 static inline void list_init(list *l)
62 node *head = &l->head;
63 head->next = head->prev = head;