lsfd: move list_free() to list.h
This commit is contained in:
parent
6f5e8c7ccf
commit
7444424d08
2 changed files with 19 additions and 11 deletions
|
@ -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); \
|
for (pos = (head)->next, pnext = pos->next; pos != (head); \
|
||||||
pos = pnext, pnext = pos->next)
|
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)
|
_INLINE_ size_t list_count_entries(struct list_head *head)
|
||||||
{
|
{
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
|
|
|
@ -33,17 +33,6 @@
|
||||||
/*
|
/*
|
||||||
* Utilities
|
* 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)));
|
DIR *opendirf(const char *format, ...) __attribute__((format (printf, 1, 2)));
|
||||||
FILE *fopenf(const char *mode, const char *format, ...) __attribute__((format (printf, 2, 3)));
|
FILE *fopenf(const char *mode, const char *format, ...) __attribute__((format (printf, 2, 3)));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue