summaryrefslogtreecommitdiff
path: root/src/util.h
blob: 923b66fa04a0bd4d6780a38ff9adc59d3b2f0fef (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef _UTIL_H_
#define _UTIL_H_

#include <stdio.h>
#include <string.h>
#include <errno.h>

#define likely(x)       __builtin_expect(!!(x), 1)
#define unlikely(x)     __builtin_expect(!!(x), 0)

extern int verbose;

#define pr_v(level, fmt, ...) do {				\
		if (verbose >= level) {				\
			fprintf(stdout, "\x1b[1m\x1b[34m"	\
				"%s(): \x1b[0m" fmt,	\
				__func__, ##__VA_ARGS__);	\
		}						\
	} while (0)

#define pr_v1(fmt, ...) pr_v(1, fmt, ##__VA_ARGS__)
#define pr_v2(fmt, ...) pr_v(2, fmt, ##__VA_ARGS__)
#define pr_v3(fmt, ...) pr_v(3, fmt, ##__VA_ARGS__)


#define pr_info(fmt, ...) fprintf(stdout, "%s(): " fmt,		\
                                  __func__, ##__VA_ARGS__)

#define pr_warn(fmt, ...) fprintf(stderr, "\x1b[1m\x1b[33m"	\
				  "WARN:%s(): " fmt "\x1b[0m",	\
				  __func__, ##__VA_ARGS__)

#define pr_err(fmt, ...) fprintf(stderr, "\x1b[1m\x1b[31m"	\
				 "ERR:%s(): " fmt "\x1b[0m",	\
				 __func__, ##__VA_ARGS__)

#ifdef DEBUG
#define pr_debug(fmt, ...) fprintf(stderr, "\x1b[1m\x1b[33m"    \
				"DEBUG:%s(): " fmt "\x1b[0m",	\
				__func__, ##__VA_ARGS__);
#else
#define pr_debug(fmt, ...)
#endif

#define strerrno() strerror(errno)

#endif /* _UTIL_H_ */