a82bdfe3247db447c0df1d9bdbc6bea176bfb165
[gapil.git] / sources / macros.h
1 /*
2  * Endianess conversion for int and short types
3  */
4 #define BE32_TO_LE32(val) ({typeof (val) v= (val);  \
5         (v>>24) | ((v>>8)&0xFF00) | (v<<24) | ((v<<8)&0xFF0000); } )
6 #define BE16_TO_LE16(val) ({typeof (val) v= (val);  (v>>8) | (v<<8); } )
7 /* 
8  * Define a protected, right typed, no side effects macro for min
9  */
10 #define min(x, y) ({typeof (x) x_ = (x); typeof (y) y_ = (y); \
11                   x_ < y_ ? x_ : y_;}) 
12 /* 
13  * debugging print definition
14  */
15 #ifdef IS_DAEMON
16 #define report(fmt, args...) UserNotify(fmt,##args)
17 #else
18 #define report(fmt, args...) printf(fmt,##args)
19 #endif /* IS_DAEMON */
20
21 #ifdef DEBUG                     /* done only on debugging */
22 #define debug  report
23 #else
24 #define debug(fmt, arg...)
25 #endif /* DEBUG */
26
27
28 /*
29  * Just to print an hex dump of a buffer,
30  * ptr is the address, m is how many word per line
31  * and l how many lines
32  */
33 #define PRINT_BUF(ptr, l, m) ({ \
34     int _i, _j; \
35     unsigned short *_ptr= (unsigned short *)(ptr); \
36     for (_i = 0; _i< (int) l; _i++) { \
37         printf("Val[%d]=", m * _i); \
38         for (_j = 0; _j < (int) m; _j++) { \
39             printf("%x ", *_ptr);\
40             _ptr++;\
41         }\
42         printf("\n"); \
43     }\
44 })