diff options
author | Kenny Levinsen <kl@kl.wtf> | 2020-08-30 00:05:19 +0200 |
---|---|---|
committer | Kenny Levinsen <kl@kl.wtf> | 2020-08-30 00:05:19 +0200 |
commit | c36cc962e6b3fd7bec8093756d4c3a7df9940862 (patch) | |
tree | 43afee6a471cc3366be43d434fcf7397baf0180e /common | |
parent | 5470c481134ab194f32f53fd8d5ba7c916478f74 (diff) |
linked_list: Implement linked_list_take
Diffstat (limited to 'common')
-rw-r--r-- | common/linked_list.c | 14 |
1 files changed, 14 insertions, 0 deletions
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); +} |