1 #ifndef __NETIFD_UTILS_H
2 #define __NETIFD_UTILS_H
4 #include <libubox/list.h>
5 #include <libubox/avl.h>
8 #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
10 #define DPRINTF(format, ...) no_debug(format, ## __VA_ARGS__)
13 static inline void no_debug(const char *fmt
, ...)
17 #define __init __attribute__((constructor))
22 typedef void (*vlist_update_cb
)(struct vlist_tree
*tree
,
23 struct vlist_node
*node_new
,
24 struct vlist_node
*node_old
);
29 vlist_update_cb update
;
42 void __vlist_init(struct vlist_tree
*tree
, avl_tree_comp cmp
, vlist_update_cb update
, int offset
);
44 #define vlist_init(tree, cmp, update, type, node, key) \
45 __vlist_init(tree, cmp, update, offsetof(type, key) - offsetof(type, node))
47 void vlist_add(struct vlist_tree
*tree
, struct vlist_node
*node
);
48 void vlist_delete(struct vlist_tree
*tree
, struct vlist_node
*node
);
49 void vlist_flush(struct vlist_tree
*tree
);
50 void vlist_flush_all(struct vlist_tree
*tree
);
52 #define vlist_for_each_element(tree, element, node_member) \
53 avl_for_each_element(&(tree)->avl, element, node_member.avl)
56 static inline int fls(int x
)
62 if (!(x
& 0xffff0000u
)) {
66 if (!(x
& 0xff000000u
)) {
70 if (!(x
& 0xf0000000u
)) {
74 if (!(x
& 0xc0000000u
)) {
78 if (!(x
& 0x80000000u
)) {
86 int avl_strcmp(const void *k1
, const void *k2
, void *ptr
);