| |
1 #ifndef __UTIL_H__ |
| |
2 #define __UTIL_H__ |
| |
3 |
| |
4 #include <debug.h> |
| |
5 |
| |
6 #define SET_TIME(x) \ |
| |
7 do { \ |
| |
8 assert(!gettimeofday((x), NULL)); \ |
| |
9 } while(0) |
| |
10 |
| |
11 #define SET_TIMEOUT(timespec, given_timeout) /* timeout is in ms */ \ |
| |
12 do { \ |
| |
13 struct timeval* curr = (struct timeval*)(timespec); \ |
| |
14 unsigned int tout; \ |
| |
15 if (given_timeout > 100) { \ |
| |
16 tout = given_timeout; \ |
| |
17 } else { \ |
| |
18 tout = 100; \ |
| |
19 } \ |
| |
20 SET_TIME(curr); \ |
| |
21 curr->tv_sec += (tout / 1000); \ |
| |
22 curr->tv_usec /= 1000; /* set to ms */ \ |
| |
23 curr->tv_usec += (tout % 1000); \ |
| |
24 curr->tv_sec += (curr->tv_usec / 1000); \ |
| |
25 curr->tv_usec = (curr->tv_usec % 1000); \ |
| |
26 curr->tv_usec *= 1000000; \ |
| |
27 } while (0) |
| |
28 |
| |
29 #endif |
| |
30 |
| |
31 /* -- gcc specific vararg macro support ... but its so nice! -- */ |
| |
32 #ifdef _DEBUG_ |
| |
33 #define Debug(x, args...) \ |
| |
34 do { \ |
| |
35 printf(x, ## args); \ |
| |
36 gaim_debug(GAIM_DEBUG_INFO, "crazychat", x, ## args); \ |
| |
37 } while (0) |
| |
38 #else |
| |
39 #define Debug(x, args...) do{}while(0) |
| |
40 #endif |