From 82d947a8321737108f545a25f91d7d50d10e831d Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Fri, 20 Jan 2017 12:57:18 +0100 Subject: lib: Add move operation for lists Allows moving the elements of one linked list to another. Re-initializes the source list. --- src/lib/list.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/lib/list.c b/src/lib/list.c index 908d3b71..01fdf6e3 100644 --- a/src/lib/list.c +++ b/src/lib/list.c @@ -70,3 +70,14 @@ bool list_is_empty(struct list_head * h) { return h->nxt == h; } + +void list_move(struct list_head * dst, + struct list_head * src) +{ + dst->nxt = src->nxt; + dst->prv = src->prv; + dst->nxt->prv = src->nxt->prv; + dst->prv->nxt = src->prv->nxt; + + list_head_init(src); +} -- cgit v1.2.3