common.h 622 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef COMMON_H
  2. #define COMMON_H
  3. #include <stdio.h>
  4. #include <errno.h>
  5. #define UNUSED __attribute__((unused))
  6. #define FIRST_ARG(N, ...) N
  7. #define ALL_ARGS(N, ...) __VA_ARGS__
  8. #define _mprint(clr, ...) \
  9. mprint(clr, "%s:%i %s():" FIRST_ARG(__VA_ARGS__) ":%s" , __FILE__, __LINE__, __func__, strerror(errno))
  10. #define perr(...) \
  11. _mprint(P_ERROR, ##__VA_ARGS__)
  12. #define pwarn(...) \
  13. _mprint(P_WARNING, ##__VA_ARGS__)
  14. #define pinfo(...) \
  15. _mprint(P_INFO, ##__VA_ARGS__)
  16. #define fail_if(A, ...) { \
  17. if(A){perr(__VA_ARGS__); goto fail;}}
  18. #define fail(...) { \
  19. perr(__VA_ARGS__); goto fail;}
  20. #endif // COMMON_H