nl80211: Fix a typo
[hostap-gosc2009.git] / src / utils / list.h
blobed7c0227264f879123a2e6ee1a2efacc6dfc65d3
1 /*
2 * Doubly-linked list
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #ifndef LIST_H
16 #define LIST_H
18 /**
19 * struct dl_list - Doubly-linked list
21 struct dl_list {
22 struct dl_list *next;
23 struct dl_list *prev;
26 static inline void dl_list_init(struct dl_list *list)
28 list->next = list;
29 list->prev = list;
32 static inline void dl_list_add(struct dl_list *list, struct dl_list *item)
34 item->next = list->next;
35 item->prev = list;
36 list->next->prev = item;
37 list->next = item;
40 static inline void dl_list_add_tail(struct dl_list *list, struct dl_list *item)
42 dl_list_add(list->prev, item);
45 static inline void dl_list_del(struct dl_list *item)
47 item->next->prev = item->prev;
48 item->prev->next = item->next;
49 item->next = NULL;
50 item->prev = NULL;
53 static inline int dl_list_empty(struct dl_list *list)
55 return list->next == list;
58 static inline unsigned int dl_list_len(struct dl_list *list)
60 struct dl_list *item;
61 int count = 0;
62 for (item = list->next; item != list; item = item->next)
63 count++;
64 return count;
67 #ifndef offsetof
68 #define offsetof(type, member) ((long) &((type *) 0)->member)
69 #endif
71 #define dl_list_entry(item, type, member) \
72 ((type *) ((char *) item - offsetof(type, member)))
74 #define dl_list_first(list, type, member) \
75 (dl_list_empty((list)) ? NULL : \
76 dl_list_entry((list)->next, type, member))
78 #define dl_list_for_each(item, list, type, member) \
79 for (item = dl_list_entry((list)->next, type, member); \
80 &item->member != (list); \
81 item = dl_list_entry(item->member.next, type, member))
83 #define dl_list_for_each_safe(item, n, list, type, member) \
84 for (item = dl_list_entry((list)->next, type, member), \
85 n = dl_list_entry(item->member.next, type, member); \
86 &item->member != (list); \
87 item = n, n = dl_list_entry(n->member.next, type, member))
89 #endif /* LIST_H */