wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
list.h
Go to the documentation of this file.
1 
5 #ifndef LIST_H
6 #define LIST_H
7 
12 struct dl_list {
13  struct dl_list *next;
14  struct dl_list *prev;
15 };
16 
17 #define DL_LIST_HEAD_INIT(l) { &(l), &(l) }
18 
19 static inline void dl_list_init(struct dl_list *list)
20 {
21  list->next = list;
22  list->prev = list;
23 }
24 
25 static inline void dl_list_add(struct dl_list *list, struct dl_list *item)
26 {
27  item->next = list->next;
28  item->prev = list;
29  list->next->prev = item;
30  list->next = item;
31 }
32 
33 static inline void dl_list_add_tail(struct dl_list *list, struct dl_list *item)
34 {
35  dl_list_add(list->prev, item);
36 }
37 
38 static inline void dl_list_del(struct dl_list *item)
39 {
40  item->next->prev = item->prev;
41  item->prev->next = item->next;
42  item->next = NULL;
43  item->prev = NULL;
44 }
45 
46 static inline int dl_list_empty(struct dl_list *list)
47 {
48  return list->next == list;
49 }
50 
51 static inline unsigned int dl_list_len(struct dl_list *list)
52 {
53  struct dl_list *item;
54  int count = 0;
55  for (item = list->next; item != list; item = item->next)
56  count++;
57  return count;
58 }
59 
60 #ifndef offsetof
61 #define offsetof(type, member) ((long) &((type *) 0)->member)
62 #endif
63 
64 #define dl_list_entry(item, type, member) \
65  ((type *) ((char *) item - offsetof(type, member)))
66 
67 #define dl_list_first(list, type, member) \
68  (dl_list_empty((list)) ? NULL : \
69  dl_list_entry((list)->next, type, member))
70 
71 #define dl_list_last(list, type, member) \
72  (dl_list_empty((list)) ? NULL : \
73  dl_list_entry((list)->prev, type, member))
74 
75 #define dl_list_for_each(item, list, type, member) \
76  for (item = dl_list_entry((list)->next, type, member); \
77  &item->member != (list); \
78  item = dl_list_entry(item->member.next, type, member))
79 
80 #define dl_list_for_each_safe(item, n, list, type, member) \
81  for (item = dl_list_entry((list)->next, type, member), \
82  n = dl_list_entry(item->member.next, type, member); \
83  &item->member != (list); \
84  item = n, n = dl_list_entry(n->member.next, type, member))
85 
86 #define dl_list_for_each_reverse(item, list, type, member) \
87  for (item = dl_list_entry((list)->prev, type, member); \
88  &item->member != (list); \
89  item = dl_list_entry(item->member.prev, type, member))
90 
91 #define DEFINE_DL_LIST(name) \
92  struct dl_list name = { &(name), &(name) }
93 
94 #endif /* LIST_H */
Doubly-linked list.
Definition: list.h:12