aboutsummaryrefslogtreecommitdiff
path: root/src/utils/dbg_log.h
blob: c30993a613b6e1b401ca244cff90e4c6758b14d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>

void (*nissy_log)(const char *);
void write_wrapper(void (*)(const char *), const char *, ...);

void
write_wrapper(void (*write)(const char *), const char *str, ...)
{
	static const size_t len = 1000;
	char message[len];
	va_list args;

	va_start(args, str);
	sprintf(message, str, args);
	va_end(args);

	write(message);
}

#define LOG(...) if (nissy_log != NULL) write_wrapper(nissy_log, __VA_ARGS__);

#ifdef DEBUG
#define STATIC
#define STATIC_INLINE
#define DBG_WARN(condition, ...) if (!(condition)) LOG(__VA_ARGS__);
#define DBG_ASSERT(condition, retval, ...) \
    if (!(condition)) { LOG(__VA_ARGS__); return retval; }
#else
#define STATIC static
#define STATIC_INLINE static inline
#define DBG_WARN(condition, ...)
#define DBG_ASSERT(condition, retval, ...)
#endif

Generated with cgit - Back to sebastiano.tronto.net