From c36cc962e6b3fd7bec8093756d4c3a7df9940862 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sun, 30 Aug 2020 00:05:19 +0200 Subject: linked_list: Implement linked_list_take --- common/linked_list.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'common') diff --git a/common/linked_list.c b/common/linked_list.c index cb3e0a8..3d2ee7d 100644 --- a/common/linked_list.c +++ b/common/linked_list.c @@ -32,3 +32,17 @@ bool linked_list_empty(struct linked_list *list) { assert(list->prev != NULL && list->next != NULL); return list->next == list; } + +void linked_list_take(struct linked_list *target, struct linked_list *source) { + if (linked_list_empty(source)) { + linked_list_init(target); + return; + } + + target->next = source->next; + target->prev = source->prev; + target->next->prev = target; + target->prev->next = target; + + linked_list_init(source); +} -- cgit v1.2.3