]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[list] Add list_check_contains()
authorMichael Brown <mcb30@ipxe.org>
Tue, 3 May 2011 19:02:07 +0000 (20:02 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 3 May 2011 19:02:07 +0000 (20:02 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/list.h

index ab4c119dd775e93dfc003d757a324778ab62de1e..4905aaa3a7bfa04249db021d604867675f8c9a6e 100644 (file)
@@ -212,4 +212,23 @@ static inline int list_empty ( const struct list_head *list ) {
              pos = tmp,                                                      \
              tmp = list_entry ( tmp->member.next, typeof ( *tmp ), member ) )
 
+/**
+ * Check list contains a specified entry
+ *
+ * @v entry            Entry
+ * @v head             List head
+ * @v member           Name of list field within iterator's type
+ */
+#define list_check_contains( entry, head, member ) do {                \
+       if ( ASSERTING ) {                                      \
+               typeof ( entry ) tmp;                           \
+               int found = 0;                                  \
+               list_for_each_entry ( tmp, head, member ) {     \
+                       if ( tmp == entry )                     \
+                               found = 1;                      \
+               }                                               \
+               assert ( found );                               \
+       }                                                       \
+       } while ( 0 )
+
 #endif /* _IPXE_LIST_H */