From 4935e526528f98c792a0ae39cfc380dd3c99575b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 14 Mar 2024 08:49:33 +1000 Subject: [PATCH] util: add a LIST_INIT macro Necessary for the case where we need a compile-time initialized list. Part-of: --- src/util-list.c | 3 +-- 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