From: Jaroslav Kysela Date: Tue, 18 Nov 2025 13:37:45 +0000 (+0100) Subject: include: list.h - add list_splice() and list_splice_init() functions X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=a525015e3bf967ab85068baeb05a8ca649192afb;p=alsa-lib.git include: list.h - add list_splice() and list_splice_init() functions Signed-off-by: Jaroslav Kysela --- diff --git a/include/list.h b/include/list.h index 7f0cfc0c..29edac04 100644 --- a/include/list.h +++ b/include/list.h @@ -114,4 +114,39 @@ static inline int list_empty(const struct list_head *p) return p->next == p; } +/* list_splice - join two lists + * @list: the new list to add + * @head: the place to add it in the first list + */ +static inline void list_splice(const struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) { + struct list_head *first = list->next; + struct list_head *last = list->prev; + struct list_head *at = head->next; + + first->prev = head; + head->next = first; + + last->next = at; + at->prev = last; + } +} + +/* list_splice_init - join two lists and reinitialize the emptied list + * @list: the new list to add + * @head: the place to add it in the first list + * + * The list at @list is reinitialized + */ +static inline void list_splice_init(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) { + list_splice(list, head); + INIT_LIST_HEAD(list); + } +} + #endif /* _LIST_H */