Replace brctl with ip (remove bridge-utils dependency)
[platform/core/security/vasum.git] / wrapper / vasum_list.h
1 #ifndef __VASUM_ADT_LIST_H__
2 #define __VASUM_ADT_LIST_H__
3
4 struct adt_list {
5     struct adt_list* next;
6     struct adt_list* prev;
7 };
8
9 #undef offsetof
10 #ifdef __compiler_offsetof
11 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
12 #else
13 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
14 #endif
15
16 #define container_of(ptr, type, member) ({                      \
17         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
18         (type *)( (char *)__mptr - offsetof(type,member) );})
19
20 #define adt_iterate_list(__iterator, __list)    \
21     for (__iterator = (__list)->next;   \
22          __iterator != __list;      \
23          __iterator = (__iterator)->next)
24
25 #define adt_reverse_iterate_list(__iterator, __list)    \
26     for (__iterator = __list;    \
27          (__iterator)->next != __list;      \
28          __iterator = (__iterator)->next);    \
29     for ( ;    \
30          __iterator != __list;      \
31          __iterator = (__iterator)->prev)
32
33 #define ADT_INIT_LIST(name) { &(name), &(name) }
34
35 static inline void adt_init_list(struct adt_list* list)
36 {
37     list->next = list->prev = list;
38 }
39
40 static inline int adt_empty_list(struct adt_list* list)
41 {
42     return (list == list->next) && (list == list->prev);
43 }
44
45 static inline void __adt_list_add(struct adt_list* _new,
46                                   struct adt_list* prev,
47                                   struct adt_list* next)
48 {
49     next->prev = _new;
50     _new->next = next;
51     _new->prev = prev;
52     prev->next = _new;
53 }
54
55 static inline void adt_link_list(struct adt_list* head, struct adt_list* list)
56 {
57     __adt_list_add(list, head, head->next);
58 }
59
60 static inline void adt_unlink_list(struct adt_list* list)
61 {
62     struct adt_list* next, *prev;
63
64     next = list->next;
65     prev = list->prev;
66     next->prev = prev;
67     prev->next = next;
68 }
69
70 static inline void adt_sort_list(struct adt_list* head,
71         int (*compare_func)(struct adt_list *, struct adt_list *))
72 {
73     struct adt_list *it, *jt, *kt;
74
75     if (adt_empty_list(head))
76         return;
77
78     for (it = head->next->next; it != head; it = it->next) {
79         for (jt = head->next; jt != it; jt = jt->next) {
80             if (compare_func(it, jt) < 0) {
81                 kt = it;
82                 it = it->prev;
83                 adt_unlink_list(kt);
84                 adt_link_list(jt->prev, kt);
85                 break;
86             }
87         }
88     }
89 }
90
91 static inline struct adt_list *adt_find_list(struct adt_list* head,
92         int (*equal_func)(struct adt_list *, void *), void *value)
93 {
94     struct adt_list *it;
95     adt_iterate_list(it, head) {
96         if (equal_func(it, value))
97             return it;
98     }
99     return NULL;
100 }
101
102 #endif /*!__VASUM_ADT_LIST_H__*/