From 829aec8055520e478edc6f040a474bca12414e0e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 7 Apr 2025 11:49:15 +1000 Subject: [PATCH] util: add a list helper for handing a pointer to a list Effectively a combination of list_append() and steal. Part-of: --- src/util-list.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/util-list.h b/src/util-list.h index bc710a9c..88b39832 100644 --- a/src/util-list.h +++ b/src/util-list.h @@ -80,6 +80,34 @@ void list_insert(struct list *list, struct list *elm); */ void list_append(struct list *list, struct list *elm); +/** + * Takes the given pointer ands inserts it to the list with the pointer's field. + * The pointer is reset to NULL. Use this to prevent automatic cleanup + * of the pointer type. + * + * @code + * list_take_insert(&f->list_of_bars, b, link); + * @endcode + */ +#define list_take_insert(list_, ptr_, field_) do {\ + list_insert(list_, &(ptr_)->field_); \ + ptr_ = NULL; \ +} while(0) + +/** + * Takes the given pointer ands adds it to the list with the pointer's field. + * The pointer is reset to NULL. Use this to prevent automatic cleanup + * of the pointer type. + * + * @code + * list_take_append(&f->list_of_bars, b, link); + * @endcode + */ +#define list_take_append(list_, ptr_, field_) do {\ + list_append(list_, &(ptr_)->field_); \ + ptr_ = NULL; \ +} while(0) + /** * Remove an element from list. *