X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftlist%2Ftlist.h;h=28978514678d99a7df24ca66872465cf0cea3586;hb=3da02efb4c0e0694ae773289d09162f59251a1f4;hp=3576146c04f1a82488d2f4f707d1ca7b6b06798d;hpb=6a906358d922800c7358c5c46c34bf4a5e6863ad;p=ccan diff --git a/ccan/tlist/tlist.h b/ccan/tlist/tlist.h index 3576146c..28978514 100644 --- a/ccan/tlist/tlist.h +++ b/ccan/tlist/tlist.h @@ -178,32 +178,64 @@ /** * tlist_top - get the first entry in a list * @h: the tlist - * @type: the type of the entry * @member: the list_node member of the type * * If the list is empty, returns NULL. * * Example: * struct child *first; - * first = tlist_top(&parent->children, struct child, list); + * first = tlist_top(&parent->children, list); + * if (!first) + * printf("Empty list!\n"); */ -#define tlist_top(h, type, member) \ - list_top(tlist_raw((h), (type *)NULL), type, member) +#define tlist_top(h, member) \ + ((tcon_type((h), canary)) \ + list_top_(&(h)->raw, \ + (char *)(&(h)->_tcon[0].canary->member) - \ + (char *)((h)->_tcon[0].canary))) /** * tlist_tail - get the last entry in a list * @h: the tlist - * @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 = tlist_tail(&parent->children, struct child, list); + * last = tlist_tail(&parent->children, list); + * if (!last) + * printf("Empty list!\n"); */ -#define tlist_tail(h, type, member) \ - list_tail(tlist_raw((h), (type *)NULL), type, member) +#define tlist_tail(h, member) \ + ((tcon_type((h), canary)) \ + list_tail_(&(h)->raw, \ + (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.