1 #ifndef __NETIFD_UTILS_H
2 #define __NETIFD_UTILS_H
4 #include <libubox/list.h>
5 #include <libubox/avl.h>
6 #include <libubox/blobmsg.h>
9 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
11 extern int __build_bug_on_failed;
12 #define BUILD_BUG_ON(condition) \
14 ((void)sizeof(char[1 - 2*!!(condition)])); \
15 if (condition) __build_bug_on_failed = 1; \
19 static inline bool blobmsg_get_bool_default(struct blob_attr *attr, bool val)
24 return blobmsg_get_bool(attr);
27 #define __init __attribute__((constructor))
32 typedef void (*vlist_update_cb)(struct vlist_tree *tree,
33 struct vlist_node *node_new,
34 struct vlist_node *node_old);
39 vlist_update_cb update;
51 void vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update);
53 #define vlist_find(tree, name, element, node_member) \
54 avl_find_element(&(tree)->avl, name, element, node_member.avl)
56 static inline void vlist_update(struct vlist_tree *tree)
61 void vlist_add(struct vlist_tree *tree, struct vlist_node *node, void *key);
62 void vlist_delete(struct vlist_tree *tree, struct vlist_node *node);
63 void vlist_flush(struct vlist_tree *tree);
64 void vlist_flush_all(struct vlist_tree *tree);
66 #define vlist_for_each_element(tree, element, node_member) \
67 avl_for_each_element(&(tree)->avl, element, node_member.avl)
70 struct vlist_simple_tree {
71 struct list_head list;
76 struct vlist_simple_node {
77 struct list_head list;
81 #define vlist_simple_init(tree, node, member) \
82 __vlist_simple_init(tree, offsetof(node, member))
84 void __vlist_simple_init(struct vlist_simple_tree *tree, int offset);
85 void vlist_simple_delete(struct vlist_simple_tree *tree, struct vlist_simple_node *node);
86 void vlist_simple_flush(struct vlist_simple_tree *tree);
87 void vlist_simple_flush_all(struct vlist_simple_tree *tree);
89 static inline void vlist_simple_update(struct vlist_simple_tree *tree)
94 static inline void vlist_simple_add(struct vlist_simple_tree *tree, struct vlist_simple_node *node)
96 list_add(&node->list, &tree->list);
99 #define vlist_simple_for_each_element(tree, element, node_member) \
100 list_for_each_entry(element, &(tree)->list, node_member.list)
102 #define vlist_simple_empty(tree) \
103 list_empty(&(tree)->list)
107 static inline int fls(int x)
113 if (!(x & 0xffff0000u)) {
117 if (!(x & 0xff000000u)) {
121 if (!(x & 0xf0000000u)) {
125 if (!(x & 0xc0000000u)) {
129 if (!(x & 0x80000000u)) {
137 int avl_strcmp(const void *k1, const void *k2, void *ptr);