aboutsummaryrefslogtreecommitdiff
path: root/common/linked_list.c
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-08-30 00:05:19 +0200
committerKenny Levinsen <kl@kl.wtf>2020-08-30 00:05:19 +0200
commitc36cc962e6b3fd7bec8093756d4c3a7df9940862 (patch)
tree43afee6a471cc3366be43d434fcf7397baf0180e /common/linked_list.c
parent5470c481134ab194f32f53fd8d5ba7c916478f74 (diff)
linked_list: Implement linked_list_take
Diffstat (limited to 'common/linked_list.c')
-rw-r--r--common/linked_list.c14
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);
+}