list.h
Go to the documentation of this file.
00001 /*
00002  * Doubly-linked list
00003  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #ifndef LIST_H
00016 #define LIST_H
00017 
00021 struct dl_list {
00022         struct dl_list *next;
00023         struct dl_list *prev;
00024 };
00025 
00026 static inline void dl_list_init(struct dl_list *list)
00027 {
00028         list->next = list;
00029         list->prev = list;
00030 }
00031 
00032 static inline void dl_list_add(struct dl_list *list, struct dl_list *item)
00033 {
00034         item->next = list->next;
00035         item->prev = list;
00036         list->next->prev = item;
00037         list->next = item;
00038 }
00039 
00040 static inline void dl_list_add_tail(struct dl_list *list, struct dl_list *item)
00041 {
00042         dl_list_add(list->prev, item);
00043 }
00044 
00045 static inline void dl_list_del(struct dl_list *item)
00046 {
00047         item->next->prev = item->prev;
00048         item->prev->next = item->next;
00049         item->next = NULL;
00050         item->prev = NULL;
00051 }
00052 
00053 static inline int dl_list_empty(struct dl_list *list)
00054 {
00055         return list->next == list;
00056 }
00057 
00058 static inline unsigned int dl_list_len(struct dl_list *list)
00059 {
00060         struct dl_list *item;
00061         int count = 0;
00062         for (item = list->next; item != list; item = item->next)
00063                 count++;
00064         return count;
00065 }
00066 
00067 #ifndef offsetof
00068 #define offsetof(type, member) ((long) &((type *) 0)->member)
00069 #endif
00070 
00071 #define dl_list_entry(item, type, member) \
00072         ((type *) ((char *) item - offsetof(type, member)))
00073 
00074 #define dl_list_first(list, type, member) \
00075         (dl_list_empty((list)) ? NULL : \
00076          dl_list_entry((list)->next, type, member))
00077 
00078 #define dl_list_for_each(item, list, type, member) \
00079         for (item = dl_list_entry((list)->next, type, member); \
00080              &item->member != (list); \
00081              item = dl_list_entry(item->member.next, type, member))
00082 
00083 #define dl_list_for_each_safe(item, n, list, type, member) \
00084         for (item = dl_list_entry((list)->next, type, member), \
00085                      n = dl_list_entry(item->member.next, type, member); \
00086              &item->member != (list); \
00087              item = n, n = dl_list_entry(n->member.next, type, member))
00088 
00089 #endif /* LIST_H */


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:33:20