dbg_log.h (859B)
1 #include <stdio.h> 2 3 void (*nissy_log)(const char *, void *); 4 void *nissy_log_data; 5 void write_wrapper(void (*)(const char *, void *), const char *, ...); 6 7 void 8 write_wrapper(void (*write)(const char *, void *), const char *str, ...) 9 { 10 static const size_t len = 1000; 11 char message[len]; 12 va_list args; 13 14 va_start(args, str); 15 vsprintf(message, str, args); 16 va_end(args); 17 18 write(message, nissy_log_data); 19 } 20 21 #define LOG(...) if (nissy_log != NULL) write_wrapper(nissy_log, __VA_ARGS__); 22 23 #ifdef DEBUG 24 #define STATIC 25 #define STATIC_INLINE 26 #define DBG_WARN(condition, ...) if (!(condition)) LOG(__VA_ARGS__); 27 #define DBG_ASSERT(condition, retval, ...) \ 28 if (!(condition)) { LOG(__VA_ARGS__); return retval; } 29 #else 30 #define STATIC static 31 #define STATIC_INLINE static inline 32 #define DBG_WARN(condition, ...) 33 #define DBG_ASSERT(condition, retval, ...) 34 #endif