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