summaryrefslogtreecommitdiff
path: root/lib/lists.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lists.c')
-rw-r--r--lib/lists.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/lists.c b/lib/lists.c
index 6d97ff50..d323a4b6 100644
--- a/lib/lists.c
+++ b/lib/lists.c
@@ -101,6 +101,46 @@ rem_node(node *n)
}
/**
+ * rem2_node - remove a node from a list, with cleanup
+ * @n: node to be removed
+ *
+ * Removes a node @n from the list it's linked in and resets its pointers to NULL.
+ * Useful if you want to distinguish between linked and unlinked nodes.
+ */
+LIST_INLINE void
+rem2_node(node *n)
+{
+ node *z = n->prev;
+ node *x = n->next;
+
+ z->next = x;
+ x->prev = z;
+ n->next = NULL;
+ n->prev = NULL;
+}
+
+/**
+ * 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
*