]> git.ozlabs.org Git - petitboot/blob - lib/list/list.h
3858cf6f1a287bed6cfdac209f16de4dc3f4c286
[petitboot] / lib / list / list.h
1 #ifndef _LIST_H
2 #define _LIST_H
3
4 struct list_item {
5         struct list_item *prev, *next;
6 };
7
8 struct list {
9         struct list_item head;
10 };
11
12 #ifndef container_of
13 #define container_of(ptr, type, member) ({                      \
14         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
15         (type *)( (char *)__mptr - offsetof(type,member) );})
16 #endif
17
18 #ifndef offsetof
19 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
20 #endif
21
22 #define list_for_each(list, pos) \
23         for (pos = (list)->head.next; pos != ((list)->head); pos = pos->next)
24
25 #define list_entry(ptr, type, member) \
26         container_of(ptr, type, member)
27
28 #define list_for_each_entry(list, pos, member)                          \
29         for (pos = list_entry((list)->head.next, typeof(*pos), member); \
30              &pos->member != &(list)->head;     \
31              pos = list_entry(pos->member.next, typeof(*pos), member))
32
33 void list_init(struct list *list);
34
35 void list_add(struct list *list, struct list_item *item);
36
37 void list_remove(struct list_item *item);
38
39 #endif /* _LIST_H */