1 #ifndef _LINUX_LISTHELP_H
2 #define _LINUX_LISTHELP_H
5 #include "linux_list.h"
7 /* Header to do more comprehensive job than linux/list.h; assume list
8 is first entry in structure. */
10 /* Return pointer to first true entry, if any, or NULL. A macro
11 required to allow inlining of cmpfn. */
12 #define LIST_FIND(head, cmpfn, type, args...) \
14 const struct list_head *__i = (head); \
18 if (__i == (head)) { \
22 } while (!cmpfn((const type)__i , ## args)); \
26 #define LIST_FIND_W(head, cmpfn, type, args...) \
28 const struct list_head *__i = (head); \
32 if (__i == (head)) { \
36 } while (!cmpfn((type)__i , ## args)); \
41 __list_cmp_same(const void *p1, const void *p2) { return p1 == p2; }
43 /* Is this entry in the list? */
45 list_inlist(struct list_head *head, const void *entry)
47 return LIST_FIND(head, __list_cmp_same, void *, entry) != NULL;
50 /* Delete from list. */
51 #define LIST_DELETE(head, oldentry) list_del((struct list_head *)oldentry)
55 list_append(struct list_head *head, void *new)
57 list_add((new), (head)->prev);
62 list_prepend(struct list_head *head, void *new)
67 /* Insert according to ordering function; insert before first true. */
68 #define LIST_INSERT(head, new, cmpfn) \
70 struct list_head *__i; \
71 for (__i = (head)->next; \
72 !cmpfn((new), (typeof (new))__i) && __i != (head); \
74 list_add((struct list_head *)(new), __i->prev); \
77 /* If the field after the list_head is a nul-terminated string, you
78 can use these functions. */
79 static inline int __list_cmp_name(const void *i, const char *name)
81 return strcmp(name, i+sizeof(struct list_head)) == 0;
84 /* Returns false if same name already in list, otherwise does insert. */
86 list_named_insert(struct list_head *head, void *new)
88 if (LIST_FIND(head, __list_cmp_name, void *,
89 new + sizeof(struct list_head)))
91 list_prepend(head, new);
95 /* Find this named element in the list. */
96 #define list_named_find(head, name) \
97 LIST_FIND(head, __list_cmp_name, void *, name)
99 #endif /*_LISTHELP_H*/