1 /* 2 * netlink/list.h Netlink List Utilities 3 * 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 7 * of the License. 8 * 9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch> 10 */ 11 12 #ifndef NETLINK_LIST_H_ 13 #define NETLINK_LIST_H_ 14 15 #include <stddef.h> 16 17 struct nl_list_head 18 { 19 struct nl_list_head * next; 20 struct nl_list_head * prev; 21 }; 22 23 24 static inline void __nl_list_add(struct nl_list_head *obj, 25 struct nl_list_head *prev, 26 struct nl_list_head *next) 27 { 28 prev->next = obj; 29 obj->prev = prev; 30 next->prev = obj; 31 obj->next = next; 32 } 33 34 static inline void nl_list_add_tail(struct nl_list_head *obj, 35 struct nl_list_head *head) 36 { 37 __nl_list_add(obj, head->prev, head); 38 } 39 40 static inline void nl_list_add_head(struct nl_list_head *obj, 41 struct nl_list_head *head) 42 { 43 __nl_list_add(obj, head, head->next); 44 } 45 46 static inline void nl_list_del(struct nl_list_head *obj) 47 { 48 obj->next->prev = obj->prev; 49 obj->prev->next = obj->next; 50 } 51 52 static inline int nl_list_empty(struct nl_list_head *head) 53 { 54 return head->next == head; 55 } 56 57 #define nl_container_of(ptr, type, member) ({ \ 58 const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 59 (type *) ((char *) __mptr - (offsetof(type, member)));}) 60 61 #define nl_list_entry(ptr, type, member) \ 62 nl_container_of(ptr, type, member) 63 64 #define nl_list_at_tail(pos, head, member) \ 65 ((pos)->member.next == (head)) 66 67 #define nl_list_at_head(pos, head, member) \ 68 ((pos)->member.prev == (head)) 69 70 #define NL_LIST_HEAD(name) \ 71 struct nl_list_head name = { &(name), &(name) } 72 73 #define nl_list_first_entry(head, type, member) \ 74 nl_list_entry((head)->next, type, member) 75 76 #define nl_list_for_each_entry(pos, head, member) \ 77 for (pos = nl_list_entry((head)->next, typeof(*pos), member); \ 78 &(pos)->member != (head); \ 79 (pos) = nl_list_entry((pos)->member.next, typeof(*(pos)), member)) 80 81 #define nl_list_for_each_entry_safe(pos, n, head, member) \ 82 for (pos = nl_list_entry((head)->next, typeof(*pos), member), \ 83 n = nl_list_entry(pos->member.next, typeof(*pos), member); \ 84 &(pos)->member != (head); \ 85 pos = n, n = nl_list_entry(n->member.next, typeof(*n), member)) 86 87 #define nl_init_list_head(head) \ 88 do { (head)->next = (head); (head)->prev = (head); } while (0) 89 90 #endif 91
This page was automatically generated by LXR 0.3.1. • OpenWrt