]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: move list_free() to list.h
authorKarel Zak <kzak@redhat.com>
Thu, 2 Sep 2021 12:13:49 +0000 (14:13 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:54 +0000 (11:01 +0200)
include/list.h
misc-utils/lsfd.h

index 96c84e572f57118f6d44a01cd62d6b17e6f231a0..b6bbbdd8fef7020ffea3ca77b0c4e194d460ac6a 100644 (file)
@@ -208,6 +208,25 @@ _INLINE_ void list_splice(struct list_head *list, struct list_head *head)
        for (pos = (head)->next, pnext = pos->next; pos != (head); \
             pos = pnext, pnext = pos->next)
 
+/**
+ * list_free - remove all entries from list and call freefunc()
+ *             for each entry
+ * @head:       the head for your list
+ * @type:       the type of the struct this is embedded in.
+ * @member:     the name of the list_struct within the struct.
+ * @freefunc:   the list entry deallocator
+ */
+#define list_free(head, type, member, freefunc)                                \
+       do {                                                            \
+               struct list_head *__p, *__pnext;                        \
+                                                                       \
+               list_for_each_safe (__p, __pnext, (head)) {             \
+                       type *__elt = list_entry(__p, type, member);    \
+                       list_del(__p);                                  \
+                       freefunc(__elt);                        \
+               }                                                       \
+       } while (0)
+
 _INLINE_ size_t list_count_entries(struct list_head *head)
 {
        struct list_head *pos;
index c07ff02ca4dd5c579fa0cb99ff5e12b973da55c3..76802f24ea4671c187a5443c6e835b2331ad7f56 100644 (file)
 /*
  * Utilities
  */
-#define list_free(LIST,TYPE,MEMBER,FREEFN)                             \
-       do {                                                            \
-               struct list_head *__p, *__pnext;                        \
-                                                                       \
-               list_for_each_safe (__p, __pnext, (LIST)) {             \
-                       TYPE *__elt = list_entry(__p, TYPE, MEMBER);    \
-                       list_del(__p);                                  \
-                       FREEFN(__elt);                                  \
-               }                                                       \
-       } while (0)
-
 DIR *opendirf(const char *format, ...) __attribute__((format (printf, 1, 2)));
 FILE *fopenf(const char *mode, const char *format, ...) __attribute__((format (printf, 2, 3)));