diff options
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..848827d --- /dev/null +++ b/src/util.h @@ -0,0 +1,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) + +#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__) + +#define pr_debug(fmt, ...) \ + do { \ + if (unlikely(debug)) { \ + fprintf(stderr, "\x1b[1m\x1b[33m" \ + "DEBUG:%s(): " fmt "\x1b[0m", \ + __func__, ##__VA_ARGS__); \ + } \ + } while (0) + + +#define strerrno() strerror(errno) + +#endif /* _UTIL_H_ */ |