util: add a list helper for handing a pointer to a list

Effectively a combination of list_append() and steal.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
This commit is contained in:
Peter Hutterer 2025-04-07 11:49:15 +10:00
parent 76c87d2486
commit 829aec8055

View file

@ -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.
*