summaryrefslogtreecommitdiff
path: root/lib/lists.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lists.c')
-rw-r--r--lib/lists.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/lists.c b/lib/lists.c
index 6d97ff50..58ffd230 100644
--- a/lib/lists.c
+++ b/lib/lists.c
@@ -101,6 +101,27 @@ rem_node(node *n)
}
/**
+ * replace_node - replace a node in a list with another one
+ * @old: node to be removed
+ * @new: node to be inserted
+ *
+ * Replaces node @old in the list it's linked in with node @new. Node
+ * @old may be a copy of the original node, which is not accessed
+ * through the list. The function could be called with @old == @new,
+ * which just fixes neighbors' pointers in the case that the node
+ * was reallocated.
+ */
+LIST_INLINE void
+replace_node(node *old, node *new)
+{
+ old->next->prev = new;
+ old->prev->next = new;
+
+ new->prev = old->prev;
+ new->next = old->next;
+}
+
+/**
* init_list - create an empty list
* @l: list
*