X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=include%2Fwimlib%2Flist.h;h=4ac2d0b414f38e8c99d9161e9a144513256ec7c6;hp=d6bd55c11013b54dadb2d0e615882058ace32e64;hb=26c7f8bb32e4a32001d409f1693e0df016270ed5;hpb=54ab7519ebeec72c4435cc09fdaa3e8b3fb35d25 diff --git a/include/wimlib/list.h b/include/wimlib/list.h index d6bd55c1..4ac2d0b4 100644 --- a/include/wimlib/list.h +++ b/include/wimlib/list.h @@ -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.