2 * UCW Library -- Single-Linked Lists
4 * (c) 2005 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.
13 typedef struct snode {
17 typedef struct slist {
18 struct snode head, *last;
21 static inline void *slist_head(slist *l)
26 static inline void *slist_tail(slist *l)
31 static inline void *slist_next(snode *n)
36 static inline int slist_empty(slist *l)
41 #define SLIST_WALK(n,list) for(n=(void*)(list).head.next; (n); (n)=(void*)((snode*)(n))->next)
42 #define SLIST_WALK_DELSAFE(n,list,prev) for((prev)=(void*)&(list).head; (n)=(void*)((snode*)prev)->next; (prev)=(((snode*)(prev))->next==(snode*)(n) ? (void*)(n) : (void*)(prev)))
43 #define SLIST_FOR_EACH(type,n,list) for(type n=(void*)(list).head.next; n; n=(void*)((snode*)(n))->next)
45 static inline void slist_insert_after(slist *l, snode *what, snode *after)
47 what->next = after->next;
53 static inline void slist_add_head(slist *l, snode *n)
55 n->next = l->head.next;
61 static inline void slist_add_tail(slist *l, snode *n)
71 static inline void slist_init(slist *l)
73 l->head.next = l->last = NULL;
76 static inline void slist_remove_after(slist *l, snode *after)
78 snode *n = after->next;
79 after->next = n->next;
81 l->last = (after == &l->head) ? NULL : after;
84 /* Non-trivial functions */
86 void *slist_prev(slist *l, snode *n);
87 void slist_insert_before(slist *l, snode *what, snode *before);
88 void slist_remove(slist *l, snode *n);