diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-01 14:12:11 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-06 18:15:14 +1000 |
commit | c8e451a8e719ba432bcfa8976774c07307087809 (patch) | |
tree | 678b0e45593684c896aec455a748d5b53c59c6df /include | |
parent | 6acebf9e1298939593b942ec91ae9ec9e74faa19 (diff) |
include: add list_last_entry to get the tail of a list
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/list.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/include/list.h b/include/list.h index f8659f04e..73ff0bee9 100644 --- a/include/list.h +++ b/include/list.h @@ -262,6 +262,21 @@ list_is_empty(struct list *head) #define list_first_entry(ptr, type, member) \ list_entry((ptr)->next, type, member) +/** + * Retrieve the last list entry for the given listpointer. + * + * Example: + * struct foo *first; + * first = list_last_entry(&foo->mylist, struct foo, mylist); + * + * @param ptr The list head + * @param type Data type of the list element to retrieve + * @param member Member name of the struct list field in the list element. + * @return A pointer to the last list element. + */ +#define list_last_entry(ptr, type, member) \ + list_entry((ptr)->prev, type, member) + #define __container_of(ptr, sample, member) \ (void *)((char *)(ptr) \ - ((char *)&(sample)->member - (char *)(sample))) |