]> wimlib.net Git - wimlib/blobdiff - include/wimlib/list.h
Rewrite of write_stream_list(), and writing packed resources
[wimlib] / include / wimlib / list.h
index d6bd55c11013b54dadb2d0e615882058ace32e64..4ac2d0b414f38e8c99d9161e9a144513256ec7c6 100644 (file)
@@ -86,6 +86,29 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head)
        __list_add(new, head->prev, head);
 }
 
+/**
+ * list_replace - replace old entry by new one
+ * @old : the element to be replaced
+ * @new : the new element to insert
+ *
+ * If @old was empty, it will be overwritten.
+ */
+static inline void list_replace(struct list_head *old,
+                               struct list_head *new)
+{
+       new->next = old->next;
+       new->next->prev = new;
+       new->prev = old->prev;
+       new->prev->next = new;
+}
+
+static inline void list_replace_init(struct list_head *old,
+                                       struct list_head *new)
+{
+       list_replace(old, new);
+       INIT_LIST_HEAD(old);
+}
+
 /*
  * Delete a list entry by making the prev/next entries
  * point to each other.