]> wimlib.net Git - wimlib/blobdiff - include/wimlib/list.h
lz_sarray: Fix some comments
[wimlib] / include / wimlib / list.h
index 763178ba71f16fb596e3ecfcde22a03ca3f34ead..e2731d1a08778925002bdb51342284498ca1ec6b 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.
@@ -129,6 +152,15 @@ static inline int list_empty(const struct list_head *head)
        return head->next == head;
 }
 
+/**
+ * list_is_singular - tests whether a list has just one entry.
+ * @head: the list to test.
+ */
+static inline int list_is_singular(const struct list_head *head)
+{
+       return !list_empty(head) && (head->next == head->prev);
+}
+
 static inline void __list_splice(const struct list_head *list,
                                 struct list_head *prev,
                                 struct list_head *next)
@@ -243,7 +275,7 @@ static inline void list_splice_tail(struct list_head *list,
  */
 #define list_for_each_entry(pos, head, member)                         \
        for (pos = list_entry((head)->next, typeof(*pos), member);      \
-            &pos->member != (head);    \
+            &pos->member != (head);    \
             pos = list_entry(pos->member.next, typeof(*pos), member))
 
 /**
@@ -256,7 +288,7 @@ static inline void list_splice_tail(struct list_head *list,
 #define list_for_each_entry_safe(pos, n, head, member)                 \
        for (pos = list_entry((head)->next, typeof(*pos), member),      \
                n = list_entry(pos->member.next, typeof(*pos), member); \
-            &pos->member != (head);                                    \
+            &pos->member != (head);                                    \
             pos = n, n = list_entry(n->member.next, typeof(*n), member))
 
 /*
@@ -351,9 +383,9 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
  * @head:      the head for your list.
  * @member:    the name of the hlist_node within the struct.
  */
-#define hlist_for_each_entry_safe(tpos, pos, n, head, member)           \
+#define hlist_for_each_entry_safe(tpos, pos, n, head, member)           \
        for (pos = (head)->first;                                        \
-            pos && ({ n = pos->next; 1; }) &&                           \
+            pos && ({ n = pos->next; 1; }) &&                           \
                ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
             pos = n)