2 * netlink/list.h Netlink List Utilities
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
12 #ifndef NETLINK_LIST_H_
13 #define NETLINK_LIST_H_
17 struct nl_list_head
* next
;
18 struct nl_list_head
* prev
;
22 static inline void __nl_list_add(struct nl_list_head
*obj
,
23 struct nl_list_head
*prev
,
24 struct nl_list_head
*next
)
32 static inline void nl_list_add_tail(struct nl_list_head
*obj
,
33 struct nl_list_head
*head
)
35 __nl_list_add(obj
, head
->prev
, head
);
38 static inline void nl_list_add_head(struct nl_list_head
*obj
,
39 struct nl_list_head
*head
)
41 __nl_list_add(obj
, head
, head
->next
);
44 static inline void nl_list_del(struct nl_list_head
*obj
)
46 obj
->next
->prev
= obj
->prev
;
47 obj
->prev
->next
= obj
->next
;
50 static inline int nl_list_empty(struct nl_list_head
*head
)
52 return head
->next
== head
;
55 #define nl_container_of(ptr, type, member) ({ \
56 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
57 (type *)( (char *)__mptr - ((size_t) &((type *)0)->member));})
59 #define nl_list_entry(ptr, type, member) \
60 nl_container_of(ptr, type, member)
62 #define nl_list_at_tail(pos, head, member) \
63 ((pos)->member.next == (head))
65 #define nl_list_at_head(pos, head, member) \
66 ((pos)->member.prev == (head))
68 #define NL_LIST_HEAD(name) \
69 struct nl_list_head name = { &(name), &(name) }
71 #define nl_list_first_entry(head, type, member) \
72 nl_list_entry((head)->next, type, member)
74 #define nl_list_for_each_entry(pos, head, member) \
75 for (pos = nl_list_entry((head)->next, typeof(*pos), member); \
76 &(pos)->member != (head); \
77 (pos) = nl_list_entry((pos)->member.next, typeof(*(pos)), member))
79 #define nl_list_for_each_entry_safe(pos, n, head, member) \
80 for (pos = nl_list_entry((head)->next, typeof(*pos), member), \
81 n = nl_list_entry(pos->member.next, typeof(*pos), member); \
82 &(pos)->member != (head); \
83 pos = n, n = nl_list_entry(n->member.next, typeof(*n), member))
85 #define nl_init_list_head(head) \
86 do { (head)->next = (head); (head)->prev = (head); } while (0)
This page took 0.053621 seconds and 5 git commands to generate.