diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2024-03-14 08:49:33 +1000 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2024-03-18 16:25:47 +0000 |
commit | 4935e526528f98c792a0ae39cfc380dd3c99575b (patch) | |
tree | 25ec65a43ce1ca360fb7d3c21e46b3f5c205d7e9 | |
parent | 3a935507ae94aa1b1c46c77ec00a872b8a68bf79 (diff) |
util: add a LIST_INIT macro
Necessary for the case where we need a compile-time initialized list.
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/984>
-rw-r--r-- | src/util-list.c | 3 | ||||
-rw-r--r-- | src/util-list.h | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/src/util-list.c b/src/util-list.c index 45fed457..900172d2 100644 --- a/src/util-list.c +++ b/src/util-list.c @@ -34,8 +34,7 @@ void list_init(struct list *list) { - list->prev = list; - list->next = list; + *list = LIST_INIT(*list); } void diff --git a/src/util-list.h b/src/util-list.h index a9f0c87b..bc710a9c 100644 --- a/src/util-list.h +++ b/src/util-list.h @@ -62,6 +62,8 @@ struct list { struct list *next; }; +#define LIST_INIT(l) (struct list){ .prev = &(l), .next = &(l) } + /** * Initialize a list head. This function *must* be called once for each list * head. This function *must not* be called for a node to be added to a |