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