]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/list.h
make lxc_af_unix_open() safely return error on long pathnames
[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
9ebb03ad
DE
17#define lxc_list_for_each_safe(__iterator, __list, __next) \
18 for (__iterator = (__list)->next, __next = __iterator->next; \
19 __iterator != __list; \
20 __iterator = __next, __next = __next->next)
21
951cc719 22static inline void lxc_list_init(struct lxc_list *list)
0ad19a3f 23{
24 list->elem = NULL;
25 list->next = list->prev = list;
26}
27
951cc719 28static inline void lxc_list_add_elem(struct lxc_list *list, void *elem)
0ad19a3f 29{
30 list->elem = elem;
31}
32
951cc719 33static inline void *lxc_list_first_elem(struct lxc_list *list)
0ad19a3f 34{
35 return list->next->elem;
36}
37
bac89583
DL
38static inline void *lxc_list_last_elem(struct lxc_list *list)
39{
40 return list->prev->elem;
41}
42
951cc719 43static inline int lxc_list_empty(struct lxc_list *list)
0ad19a3f 44{
45 return list == list->next;
46}
47
951cc719
DL
48static inline void __lxc_list_add(struct lxc_list *new,
49 struct lxc_list *prev,
50 struct lxc_list *next)
0ad19a3f 51{
951cc719
DL
52 next->prev = new;
53 new->next = next;
54 new->prev = prev;
55 prev->next = new;
0ad19a3f 56}
57
951cc719 58static inline void lxc_list_add(struct lxc_list *head, struct lxc_list *list)
0ad19a3f 59{
951cc719
DL
60 __lxc_list_add(list, head, head->next);
61}
62
63static inline void lxc_list_add_tail(struct lxc_list *head,
64 struct lxc_list *list)
65{
66 __lxc_list_add(list, head->prev, head);
67}
68
69static inline void lxc_list_del(struct lxc_list *list)
70{
71 struct lxc_list *next, *prev;
0ad19a3f 72
73 next = list->next;
74 prev = list->prev;
75 next->prev = prev;
76 prev->next = next;
77}
78
79#endif