]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/misc-progs/list.h
1 /* list.h by Jan Bobrowski. Inspired by list.h from Linux */
7 struct list
*next
, *prev
;
10 static inline void list_link(struct list
*a
, struct list
*b
)
16 static inline void list_add(struct list
*head
, struct list
*item
)
18 struct list
*first
= head
->next
;
19 list_link(head
, item
);
20 list_link(item
, first
);
23 static inline void list_add_end(struct list
*head
, struct list
*item
)
25 struct list
*last
= head
->prev
;
26 list_link(item
, head
);
27 list_link(last
, item
);
30 static inline list_t
*list_del(struct list
*item
)
32 struct list
*prev
= item
->prev
, *next
= item
->next
;
33 list_link(prev
, next
);
37 static inline void list_init(struct list
*head
)
39 list_link(head
, head
);
42 /* delete item from one list and add it to another */
43 static inline void list_del_add(list_t
*head
, list_t
*item
)
45 list_t
*prev
= item
->prev
, *next
= item
->next
;
46 list_link(prev
, next
);
48 list_link(head
, item
);
49 list_link(item
, next
);
52 /*static inline list_check(list_t *l)
64 static inline void list_del_add_end(list_t
*head
, list_t
*item
)
66 list_t
*prev
= item
->prev
, *next
= item
->next
;
67 list_link(prev
, next
);
69 list_link(item
, head
);
74 static inline void list_del_init(struct list
*item
)
76 struct list
*prev
= item
->prev
, *next
= item
->next
;
77 list_link(item
, item
);
78 list_link(prev
, next
);
81 static inline void list_join(struct list
*a
, struct list
*b
)
91 static inline int list_empty(struct list
*head
)
93 return head
->next
== head
;
96 #define LIST(L) struct list L = {&L, &L}
98 #define list_entry(L, T, M) ((T*)((char*)(L) - (long)(&((T*)0)->M)))
99 #define list_item(L, T, M) ((T*)((char*)(L) - (long)(&((T*)0)->M)))
101 #define list_first(H, T, M) list_item((H)->next, T, M)
102 #define list_last(H, T, M) list_item((H)->prev, T, M)
103 #define list_next(O, M) list_item((O)->M.next, typeof(*(O)), M)
105 /* remove first element and return it */
106 static inline struct list
*list_get(struct list
*head
)
108 struct list
*item
= head
->next
;
109 struct list
*next
= item
->next
;
110 list_link(head
, next
);
114 /* remove first element, initialize and return it */
115 static inline struct list
*list_get_init(struct list
*head
)
117 struct list
*item
= head
->next
;
118 struct list
*next
= item
->next
;
119 list_link(item
, item
);
120 list_link(head
, next
);
124 #define list_get_entry(H, T, M) list_item(list_get((H)), T, M)
125 #define list_get_init_entry(H, T, M) list_item(list_get_init((H)), T, M)
126 #define list_get_item(H, T, M) list_item(list_get((H)), T, M)
127 #define list_get_init_item(H, T, M) list_item(list_get_init((H)), T, M)