add DPRINTF type checking for no-debug builds
[project/netifd.git] / netifd.h
1 #ifndef __NETIFD_H
2 #define __NETIFD_H
3
4 #include <sys/socket.h>
5 #include <net/if.h>
6
7 #include <stdbool.h>
8 #include <stdio.h>
9
10 #include <libubox/list.h>
11 #include <libubox/uloop.h>
12
13 #include <libubus.h>
14 #include <uci.h>
15
16 #ifdef DEBUG
17 #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
18 #else
19 #define DPRINTF(format, ...) no_debug(format, ## __VA_ARGS__)
20 #endif
21
22 static inline void no_debug(const char *fmt, ...)
23 {
24 }
25
26 #define __init __attribute__((constructor))
27
28 struct device;
29 struct interface;
30
31 extern struct uci_context *uci_ctx;
32 extern bool config_init;
33
34 int avl_strcmp(const void *k1, const void *k2, void *ptr);
35 void config_init_interfaces(const char *name);
36
37 #ifdef __linux__
38 static inline int fls(int x)
39 {
40     int r = 32;
41
42     if (!x)
43         return 0;
44     if (!(x & 0xffff0000u)) {
45         x <<= 16;
46         r -= 16;
47     }
48     if (!(x & 0xff000000u)) {
49         x <<= 8;
50         r -= 8;
51     }
52     if (!(x & 0xf0000000u)) {
53         x <<= 4;
54         r -= 4;
55     }
56     if (!(x & 0xc0000000u)) {
57         x <<= 2;
58         r -= 2;
59     }
60     if (!(x & 0x80000000u)) {
61         x <<= 1;
62         r -= 1;
63     }
64     return r;
65 }
66 #endif
67
68 #endif