8 static int random_fd
= -1;
10 static int ubus_cmp_id(const void *k1
, const void *k2
, void *ptr
)
12 const uint32_t *id1
= k1
, *id2
= k2
;
20 void ubus_init_id_tree(struct avl_tree
*tree
)
23 random_fd
= open("/dev/urandom", O_RDONLY
);
30 avl_init(tree
, ubus_cmp_id
, false, NULL
);
33 bool ubus_alloc_id(struct avl_tree
*tree
, struct ubus_id
*id
)
35 id
->avl
.key
= &id
->id
;
37 if (read(random_fd
, &id
->id
, sizeof(id
->id
)) != sizeof(id
->id
))
42 } while (avl_insert(tree
, &id
->avl
) != 0);