X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Flist%2Flist.h;h=e1f07a0e043ae7f460d2650e2acdf39d468ab5aa;hp=c664d83426af36d78304ae98b33f8dd04f98c21e;hb=570c9c555f076e74f46141bb42b5d1d7ac89f632;hpb=650c775ff00cccd03fc84e7789a03c51d9839004 diff --git a/ccan/list/list.h b/ccan/list/list.h index c664d834..e1f07a0e 100644 --- a/ccan/list/list.h +++ b/ccan/list/list.h @@ -1,7 +1,7 @@ #ifndef CCAN_LIST_H #define CCAN_LIST_H #include -#include "container_of/container_of.h" +#include /** * struct list_node - an entry in a doubly-linked list @@ -198,15 +198,22 @@ static inline bool list_empty(struct list_head *h) * first = list_top(&parent->children, struct child, list); */ #define list_top(h, type, member) \ - list_entry(_list_top(h), type, member) + (list_empty(h) ? NULL : list_entry((h)->n.next, type, member)) -static inline struct list_node *_list_top(struct list_head *h) -{ - (void)debug_list(h); - if (list_empty(h)) - return NULL; - return h->n.next; -} +/** + * list_tail - get the last entry in a list + * @h: the list_head + * @type: the type of the entry + * @member: the list_node member of the type + * + * If the list is empty, returns NULL. + * + * Example: + * struct child *last; + * last = list_tail(&parent->children, struct child, list); + */ +#define list_tail(h, type, member) \ + (list_empty(h) ? NULL : list_entry((h)->n.prev, type, member)) /** * list_for_each - iterate through a list.