]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/list.h
Makefile.am: use right .h file name for seccomp
[mirror_lxc.git] / src / lxc / list.h
CommitLineData
0ad19a3f 1#ifndef _list_h
2#define _list_h
3
951cc719 4struct lxc_list {
0ad19a3f 5 void *elem;
951cc719
DL
6 struct lxc_list *next;
7 struct lxc_list *prev;
0ad19a3f 8};
9
951cc719 10#define lxc_init_list(l) { .next = l, .prev = l }
0ad19a3f 11
951cc719 12#define lxc_list_for_each(__iterator, __list) \
0ad19a3f 13 for (__iterator = (__list)->next; \
14 __iterator != __list; \
15 __iterator = __iterator->next)
16
951cc719 17static inline void lxc_list_init(struct lxc_list *list)
0ad19a3f 18{
19 list->elem = NULL;
20 list->next = list->prev = list;
21}
22
951cc719 23static inline void lxc_list_add_elem(struct lxc_list *list, void *elem)
0ad19a3f 24{
25 list->elem = elem;
26}
27
951cc719 28static inline void *lxc_list_first_elem(struct lxc_list *list)
0ad19a3f 29{
30 return list->next->elem;
31}
32
bac89583
DL
33static inline void *lxc_list_last_elem(struct lxc_list *list)
34{
35 return list->prev->elem;
36}
37
951cc719 38static inline int lxc_list_empty(struct lxc_list *list)
0ad19a3f 39{
40 return list == list->next;
41}
42
951cc719
DL
43static inline void __lxc_list_add(struct lxc_list *new,
44 struct lxc_list *prev,
45 struct lxc_list *next)
0ad19a3f 46{
951cc719
DL
47 next->prev = new;
48 new->next = next;
49 new->prev = prev;
50 prev->next = new;
0ad19a3f 51}
52
951cc719 53static inline void lxc_list_add(struct lxc_list *head, struct lxc_list *list)
0ad19a3f 54{
951cc719
DL
55 __lxc_list_add(list, head, head->next);
56}
57
58static inline void lxc_list_add_tail(struct lxc_list *head,
59 struct lxc_list *list)
60{
61 __lxc_list_add(list, head->prev, head);
62}
63
64static inline void lxc_list_del(struct lxc_list *list)
65{
66 struct lxc_list *next, *prev;
0ad19a3f 67
68 next = list->next;
69 prev = list->prev;
70 next->prev = prev;
71 prev->next = next;
72}
73
74#endif