libmooshika
utils.h
Go to the documentation of this file.
1 #define ERROR_LOG(fmt, args...) fprintf(stderr, "ERROR: %s (%d), %s: " fmt "\n", __FILE__, __LINE__, __func__, ##args)
2 //#define ERROR_LOG(fmt, args...)
3 #define INFO_LOG(debug, fmt, args...) if (debug) fprintf(stderr, "INFO: %s (%d), %s: " fmt "\n", __FILE__, __LINE__, __func__, ##args)
4 //#define INFO_LOG(fmt, args...)
5 
6 #define TEST_Z(x) do { int retval; if ( (retval=x)) { ERROR_LOG("error: " #x " failed (returned %d, errno %d).", retval, errno ); exit(retval); } } while (0)
7 #define TEST_NZ(x) do { if (!(x)) { ERROR_LOG("error: " #x " failed (returned zero/null. errno=%d).", errno); exit(-1); }} while (0)
8 
9 #include "atomics.h"
10 
11 #define set_size(val, unit) do { \
12  switch(unit[0]) { \
13  case 'k': \
14  case 'K': \
15  val *= 1024; \
16  break; \
17  case 'm': \
18  case 'M': \
19  val *= 1024 * 1024; \
20  break; \
21  case 'g': \
22  case 'G': \
23  val *= 1024 * 1024 * 1024; \
24  break; \
25  default: \
26  ERROR_LOG("unknown unit '%c'", unit[0]); \
27  val = 0; \
28  } \
29 } while (0)
30 
31 
32 #define NSEC_IN_SEC 1000000000
33 
34 static inline void sub_timespec(uint64_t *new, struct timespec *x, struct timespec *y) {
35  if (y->tv_nsec < x->tv_nsec) {
36  *new = (y->tv_sec - x->tv_sec - 1) * NSEC_IN_SEC +
37  y->tv_nsec + NSEC_IN_SEC - x->tv_nsec;
38  } else {
39  *new = (y->tv_sec - x->tv_sec) * NSEC_IN_SEC +
40  y->tv_nsec - x->tv_nsec;
41  }
42 }
43 
44 #define MSK_MAX_RESVPORT 1023
45 #define MSK_MIN_RESVPORT 512
#define NSEC_IN_SEC
Definition: utils.h:32