diff --git a/include/list.h b/include/list.h index 96c84e572..b6bbbdd8f 100644 --- a/include/list.h +++ b/include/list.h @@ -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; diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index c07ff02ca..76802f24e 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -33,17 +33,6 @@ /* * 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)));