From 5e910c7e41d18dab95e34ceb6e620a8958197ae6 Mon Sep 17 00:00:00 2001 From: kartofen Date: Mon, 16 Oct 2023 23:46:15 +0300 Subject: things done --- src/common.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/common.h (limited to 'src/common.h') diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..e10649a --- /dev/null +++ b/src/common.h @@ -0,0 +1,34 @@ +#ifndef LOG_H +#define LOG_H + +#include +#include +#include + +#define ARR_SIZE(a) (sizeof(a)/sizeof(*(a))) + +#define __RED__ "\033[0;31m" +#define __GREEN__ "\033[0;32m" +#define __YELLOW__ "\033[0;33m" +#define __RESET__ "\033[0m" + +#define STR(x) #x +#define XSTR(x) STR(x) + +#define info(...) do { fprintf(stdout, __GREEN__"[INFO]"__RESET__" "__VA_ARGS__); fprintf(stdout, "\n"); } while(0) +#define err(...) do { fprintf(stderr, __RED__"[ERROR]"__RESET__" "__FILE__":"XSTR(__LINE__)": "__VA_ARGS__); fprintf(stderr, "\n"); } while(0) +#define warn(...) do { fprintf(stderr, __YELLOW__"[WARN]"__RESET__" "__FILE__":"XSTR(__LINE__)": "__VA_ARGS__); fprintf(stderr, "\n"); } while(0) + +#define die(...) do { \ + err(__VA_ARGS__); \ + abort(); \ + } while(0) + +#define MAKE_VERSION(major, minor, patch) \ + ((((uint32_t)(major)) << 22U) | (((uint32_t)(minor)) << 12U) | ((uint32_t)(patch))) + +void *xmalloc(size_t size); +void *xcalloc(size_t nmemb, size_t size); +void *xrealloc(void *ptr, size_t size); + +#endif -- cgit v1.2.3