initial commit

This commit is contained in:
Ryo Nakamura
2022-10-15 21:59:25 +09:00
commit 303a9eb974
9 changed files with 515 additions and 0 deletions

47
src/util.h Normal file
View File

@@ -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_ */