Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / src / utils / list.h
index ed7c022..ee2f485 100644 (file)
@@ -2,14 +2,8 @@
  * Doubly-linked list
  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #ifndef LIST_H
@@ -23,6 +17,8 @@ struct dl_list {
        struct dl_list *prev;
 };
 
+#define DL_LIST_HEAD_INIT(l) { &(l), &(l) }
+
 static inline void dl_list_init(struct dl_list *list)
 {
        list->next = list;
@@ -75,6 +71,10 @@ static inline unsigned int dl_list_len(struct dl_list *list)
        (dl_list_empty((list)) ? NULL : \
         dl_list_entry((list)->next, type, member))
 
+#define dl_list_last(list, type, member) \
+       (dl_list_empty((list)) ? NULL : \
+        dl_list_entry((list)->prev, type, member))
+
 #define dl_list_for_each(item, list, type, member) \
        for (item = dl_list_entry((list)->next, type, member); \
             &item->member != (list); \
@@ -86,4 +86,12 @@ static inline unsigned int dl_list_len(struct dl_list *list)
             &item->member != (list); \
             item = n, n = dl_list_entry(n->member.next, type, member))
 
+#define dl_list_for_each_reverse(item, list, type, member) \
+       for (item = dl_list_entry((list)->prev, type, member); \
+            &item->member != (list); \
+            item = dl_list_entry(item->member.prev, type, member))
+
+#define DEFINE_DL_LIST(name) \
+       struct dl_list name = { &(name), &(name) }
+
 #endif /* LIST_H */