aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/chelper
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-09-27 18:24:18 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-11-06 15:51:51 -0500
commitc06f6943a66cff3fa20e570edc8f2aff235ae75e (patch)
tree596ac6d3c18b37b54a0df47c677158a95454f7f9 /klippy/chelper
parentfdbdb3c70777e6c953b13d5455ccab56d024b029 (diff)
downloadkutter-c06f6943a66cff3fa20e570edc8f2aff235ae75e.tar.gz
kutter-c06f6943a66cff3fa20e570edc8f2aff235ae75e.tar.xz
kutter-c06f6943a66cff3fa20e570edc8f2aff235ae75e.zip
list: Add additional list helper functions
Add list_is_first, list_is_last, list_last_entry, and list_prev_entry helper functions. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/chelper')
-rw-r--r--klippy/chelper/list.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/klippy/chelper/list.h b/klippy/chelper/list.h
index 317a109c..12fe2b03 100644
--- a/klippy/chelper/list.h
+++ b/klippy/chelper/list.h
@@ -30,6 +30,18 @@ list_empty(const struct list_head *h)
return h->root.next == &h->root;
}
+static inline int
+list_is_first(const struct list_node *n, const struct list_head *h)
+{
+ return n->prev == &h->root;
+}
+
+static inline int
+list_is_last(const struct list_node *n, const struct list_head *h)
+{
+ return n->next == &h->root;
+}
+
static inline void
list_del(struct list_node *n)
{
@@ -90,9 +102,15 @@ list_join_tail(struct list_head *add, struct list_head *h)
#define list_next_entry(pos, member) \
container_of((pos)->member.next, typeof(*pos), member)
+#define list_prev_entry(pos, member) \
+ container_of((pos)->member.prev, typeof(*pos), member)
+
#define list_first_entry(head, type, member) \
container_of((head)->root.next, type, member)
+#define list_last_entry(head, type, member) \
+ container_of((head)->root.prev, type, member)
+
#define list_for_each_entry(pos, head, member) \
for (pos = list_first_entry((head), typeof(*pos), member) \
; &pos->member != &(head)->root \