-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.h
37 lines (32 loc) · 891 Bytes
/
debug.h
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
34
35
36
37
#ifndef DEBUG_H
#define DEBUG_H __FILE__
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
static inline int __info(int cond, const char *prefix, char *f_name, int line,
const char *fmt, ...)
{
int errsv = errno;
if (!cond)
return 0;
va_list va;
va_start(va, fmt);
fprintf(stderr, "%s(%s:%d): ", prefix, f_name, line);
vfprintf(stderr, fmt, va);
fprintf(stderr, "\n");
va_end(va);
errno = errsv;
return 1;
}
#define ERR_ON(cond, ...) \
__info((cond), "Error", __FILE__, __LINE__, __VA_ARGS__)
#define ERR(...) ERR_ON(1, __VA_ARGS__)
#define WARN_ON(cond, ...) \
__info((cond), "Warning", __FILE__, __LINE__, __VA_ARGS__)
#define WARN(...) WARN_ON(1, __VA_ARGS__)
#define INFO_ON(cond, ...) \
__info((cond), "Info", __FILE__, __LINE__, __VA_ARGS__)
#define INFO(...) INFO_ON(1, __VA_ARGS__)
#define ERRSTR strerror(errno)
#endif /* DEBUG_H */