From fb53ff50a1f766321f4eae57396e1f8f70afb4f7 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 14 Apr 2019 18:29:45 +0100 Subject: [PATCH] list: add list_replace Signed-off-by: Yuxuan Shui --- src/list.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/list.h b/src/list.h index 4aca0b9d..3c9ee6c6 100644 --- a/src/list.h +++ b/src/list.h @@ -66,6 +66,13 @@ static inline void list_init_head(struct list_node *head) { head->next = head->prev = head; } +/// Replace list node `old` with `n` +static inline void list_replace(struct list_node *old, struct list_node *n) { + __list_insert_between(old->prev, old->next, n); + old->prev = (void *)-1; + old->next = (void *)-2; +} + /// Return true if head is the only node in the list. Under usual circumstances this means /// the list is empty static inline bool list_is_empty(const struct list_node *head) {