1*ad054a21SCyrill Gorcunov #ifndef UTIL_H_ 2*ad054a21SCyrill Gorcunov #define UTIL_H_ 3*ad054a21SCyrill Gorcunov 4*ad054a21SCyrill Gorcunov /* 5*ad054a21SCyrill Gorcunov * Some bits are stolen from perf tool :) 6*ad054a21SCyrill Gorcunov */ 7*ad054a21SCyrill Gorcunov 8*ad054a21SCyrill Gorcunov #include <unistd.h> 9*ad054a21SCyrill Gorcunov #include <stdio.h> 10*ad054a21SCyrill Gorcunov #include <stddef.h> 11*ad054a21SCyrill Gorcunov #include <stdlib.h> 12*ad054a21SCyrill Gorcunov #include <stdarg.h> 13*ad054a21SCyrill Gorcunov #include <string.h> 14*ad054a21SCyrill Gorcunov #include <errno.h> 15*ad054a21SCyrill Gorcunov #include <limits.h> 16*ad054a21SCyrill Gorcunov #include <sys/param.h> 17*ad054a21SCyrill Gorcunov #include <sys/types.h> 18*ad054a21SCyrill Gorcunov 19*ad054a21SCyrill Gorcunov #ifdef __GNUC__ 20*ad054a21SCyrill Gorcunov #define NORETURN __attribute__((__noreturn__)) 21*ad054a21SCyrill Gorcunov #else 22*ad054a21SCyrill Gorcunov #define NORETURN 23*ad054a21SCyrill Gorcunov #ifndef __attribute__ 24*ad054a21SCyrill Gorcunov #define __attribute__(x) 25*ad054a21SCyrill Gorcunov #endif 26*ad054a21SCyrill Gorcunov #endif 27*ad054a21SCyrill Gorcunov 28*ad054a21SCyrill Gorcunov #define __stringify_1(x) #x 29*ad054a21SCyrill Gorcunov #define __stringify(x) __stringify_1(x) 30*ad054a21SCyrill Gorcunov 31*ad054a21SCyrill Gorcunov extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); 32*ad054a21SCyrill Gorcunov extern void die_perror(const char *s) NORETURN; 33*ad054a21SCyrill Gorcunov extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); 34*ad054a21SCyrill Gorcunov extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); 35*ad054a21SCyrill Gorcunov extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN); 36*ad054a21SCyrill Gorcunov 37*ad054a21SCyrill Gorcunov #define DIE_IF(cnd) \ 38*ad054a21SCyrill Gorcunov do { \ 39*ad054a21SCyrill Gorcunov if (cnd) \ 40*ad054a21SCyrill Gorcunov die(" at (" __FILE__ ":" __stringify(__LINE__) "): " \ 41*ad054a21SCyrill Gorcunov __stringify(cnd) "\n"); \ 42*ad054a21SCyrill Gorcunov } while (0) 43*ad054a21SCyrill Gorcunov 44*ad054a21SCyrill Gorcunov #endif /* UTIL_H_ */ 45