6 list_init(struct list* l)
13 list_is_empty(struct list* l)
15 return (&l->head==l->head.next);
18 /* return first element of the list or NULL if empty */
20 list_first(struct list* l)
22 return (&l->head!=l->head.next?l->head.next:NULL);
26 list_last(struct list* l)
28 return (&l->head!=l->head.prev?l->head.prev:NULL);
32 list_prev(struct list* l, struct node* n)
34 return (n->prev!=&l->head?n->prev:NULL);
38 list_next(struct list* l, struct node* n)
40 return (n->next!=&l->head?n->next:NULL);
44 list_add_first(struct list* l, struct node* new)
47 new->next=l->head.next;
48 l->head.next->prev=new;
53 list_add_last(struct list* l, struct node* new)
55 new->prev=l->head.prev;
57 l->head.prev->next=new;
62 list_add_after(struct node* orig, struct node* new)
71 list_add_before(struct node* orig, struct node* new)
80 list_del_node(struct node* n)
82 n->prev->next=n->next;
83 n->next->prev=n->prev;
88 list_del_first(struct list* l)
102 list_del_last(struct list* l)
106 if (list_is_empty(l))
116 list_cat(struct list* dst, struct list* src)
118 struct node* dst_last = dst->head.prev;
119 struct node* src_first = src->head.next;
120 struct node* src_last = src->head.prev;
122 dst_last->next = src_first;
123 src_first->prev = dst_last;
124 src_last->next = &dst->head;
125 dst->head.prev = src_last;