X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftlist%2Ftlist.h;h=28978514678d99a7df24ca66872465cf0cea3586;hb=f359fde1b7c3ca60faebd4df710bf30a68784e27;hp=1ce0b85ed9f03c01333c8412c2d260541f8724cb;hpb=a6b5111fe6948e51114c33aa34785c9fd0d403e6;p=ccan diff --git a/ccan/tlist/tlist.h b/ccan/tlist/tlist.h index 1ce0b85e..28978514 100644 --- a/ccan/tlist/tlist.h +++ b/ccan/tlist/tlist.h @@ -185,6 +185,8 @@ * Example: * struct child *first; * first = tlist_top(&parent->children, list); + * if (!first) + * printf("Empty list!\n"); */ #define tlist_top(h, member) \ ((tcon_type((h), canary)) \ @@ -202,6 +204,8 @@ * Example: * struct child *last; * last = tlist_tail(&parent->children, list); + * if (!last) + * printf("Empty list!\n"); */ #define tlist_tail(h, member) \ ((tcon_type((h), canary)) \ @@ -209,6 +213,30 @@ (char *)(&(h)->_tcon[0].canary->member) - \ (char *)((h)->_tcon[0].canary))) +/** + * tlist_next - get the next entry in a list + * @h: the tlist + * @n: the list element + * @member: the list_node member of the type + * + * Returns the element of list @h immediately after @n, or NULL, if @n + * is the last element in the list. + */ +#define tlist_next(h, n, member) \ + list_next(tlist_raw((h), (n)), (n), member) + +/** + * tlist_prev - get the previous entry in a list + * @h: the tlist + * @n: the list element + * @member: the list_node member of the type + * + * Returns the element of list @h immediately before @n, or NULL, if + * @n is the first element in the list. + */ +#define tlist_prev(h, n, member) \ + list_prev(tlist_raw((h), (n)), (n), member) + /** * tlist_for_each - iterate through a list. * @h: the tlist