09df8c6f3e03c795ff8610b275c6bc59c9a58fe1
[project/netifd.git] / utils.h
1 #ifndef __NETIFD_UTILS_H
2 #define __NETIFD_UTILS_H
3
4 #include <libubox/list.h>
5
6 #ifdef DEBUG
7 #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
8 #else
9 #define DPRINTF(format, ...) no_debug(format, ## __VA_ARGS__)
10 #endif
11
12 static inline void no_debug(const char *fmt, ...)
13 {
14 }
15
16 #define __init __attribute__((constructor))
17
18 #ifdef __linux__
19 static inline int fls(int x)
20 {
21 int r = 32;
22
23 if (!x)
24 return 0;
25 if (!(x & 0xffff0000u)) {
26 x <<= 16;
27 r -= 16;
28 }
29 if (!(x & 0xff000000u)) {
30 x <<= 8;
31 r -= 8;
32 }
33 if (!(x & 0xf0000000u)) {
34 x <<= 4;
35 r -= 4;
36 }
37 if (!(x & 0xc0000000u)) {
38 x <<= 2;
39 r -= 2;
40 }
41 if (!(x & 0x80000000u)) {
42 x <<= 1;
43 r -= 1;
44 }
45 return r;
46 }
47 #endif
48
49 int avl_strcmp(const void *k1, const void *k2, void *ptr);
50
51 #endif