#ifndef UTIL_H #define UTIL_H #include #include // utility for errors #if !DEBUG void log(const char* format, ...) __attribute__((format(printf, 1, 2))); void die(const char* format, ...) __attribute__((format(printf, 1, 2))); void* emalloc(size_t size, char* alloc_reason); #else #define log(fmt, ...) _log(__LINE__, __FILE__, fmt, ##__VA_ARGS__) void _log(int line, const char* file, const char* format, ...) __attribute__((format(printf, 3, 4))); #define die(fmt, ...) _die(__LINE__, __FILE__, fmt, ##__VA_ARGS__) void _die(int line, const char* file, const char* format, ...) __attribute__((format(printf, 3, 4))); #define emalloc(size, alloc_reason) _emalloc(__LINE__, __FILE__, size, alloc_reason) void* _emalloc(int line, const char* file, size_t size, char* alloc_reason); #endif // functions for outputting and displaying text, log is used for nonroutine bad things void printout(const char* format, ...) __attribute__((format(printf, 1, 2))); void print(const char* format, ...) __attribute__((format(printf, 1, 2))); // string functions #define vastrcat(...) vastrcat_(0, __VA_ARGS__, NULL) char* vastrcat_(int dummy, ...); // posix path functions #define join_path(...) join_path_(0, __VA_ARGS__, NULL) char* join_path_(int dummy, ...); #endif