1 #ifndef IPTRAF_NG_LIST_H
2 #define IPTRAF_NG_LIST_H
5 struct list_head
*next
, *prev
;
8 #define LIST_HEAD_INIT(name) { &(name), &(name) }
10 #define LIST_HEAD(name) \
11 struct list_head name = LIST_HEAD_INIT(name)
13 static inline void INIT_LIST_HEAD(struct list_head
*list
)
19 static inline void __list_add(struct list_head
*new, struct list_head
*prev
,
20 struct list_head
*next
)
28 static inline void list_add(struct list_head
*new, struct list_head
*head
)
30 __list_add(new, head
, head
->next
);
33 static inline void list_add_tail(struct list_head
*new, struct list_head
*head
)
35 __list_add(new, head
->prev
, head
);
38 static inline void list_add_tail_unique(struct list_head
*new,
39 struct list_head
*head
)
41 __list_add(new, head
->prev
, head
);
44 static inline void __list_del(struct list_head
*prev
, struct list_head
*next
)
50 static inline void list_del(struct list_head
*entry
)
52 __list_del(entry
->prev
, entry
->next
);
57 static inline int list_is_last(const struct list_head
*list
,
58 const struct list_head
*head
)
60 return list
->next
== head
;
63 static inline int list_empty(const struct list_head
*head
)
65 return head
->next
== head
;
68 #define list_entry(ptr, type, member) \
69 ((type *)( (char *)(ptr) - offsetof(type, member) ))
71 #define list_for_each(pos, head) \
72 for (pos = (head)->next; pos != (head); pos = pos->next)
74 #define list_for_each_safe(pos, n, head) \
75 for (pos = (head)->next, n = pos->next; pos != (head); \
76 pos = n, n = pos->next)
78 #define list_for_each_entry(pos, head, member) \
79 for (pos = list_entry((head)->next, typeof(*pos), member); \
80 &pos->member != (head); \
81 pos = list_entry(pos->member.next, typeof(*pos), member))
83 #define list_for_each_entry_safe(pos, n, head, member) \
84 for (pos = list_entry((head)->next, typeof(*pos), member), \
85 n = list_entry(pos->member.next, typeof(*pos), member); \
86 &pos->member != (head); \
87 pos = n, n = list_entry(n->member.next, typeof(*n), member))
89 #endif /* IPTRAF_NG_LIST_H */