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_head(list *l)
23 return (l->head.next != &l->head) ? l->head.next : NULL;
26 static inline void *list_tail(list *l)
28 return (l->head.prev != &l->head) ? l->head.prev : NULL;
31 static inline void *list_next(list *l, node *n)
33 return (n->next != &l->head) ? (void *) n->next : NULL;
36 static inline void *list_prev(list *l, node *n)
38 return (n->prev != &l->head) ? (void *) n->prev : NULL;
41 #define WALK_LIST(n,list) for(n=(void*)(list).head; ((node*)(n))->next != &(list).head; n=(void*)((node*)(n))->next)
43 static inline void list_insert(node *what, node *after)
45 node *before = after->next;
47 what->prev = before->prev;
52 static inline void list_add_tail(list *l, node *n)
54 list_insert(n, l->head.prev);
57 static inline void list_add_head(list *l, node *n)
59 list_insert(n, &l->head);
62 static inline void list_remove(node *n)
64 node *before = n->prev;
65 node *after = n->next;
70 static inline void list_init(list *l)
72 node *head = &l->head;
73 head->next = head->prev = head;