From 9d09d66a273f68fae7efb71504bf40c664b91983 Mon Sep 17 00:00:00 2001 From: nasr Date: Mon, 13 Apr 2026 15:33:05 +0200 Subject: feature(main): init feature(main): init feature(main): init feature(main): init --- source/base/base_error.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 source/base/base_error.h (limited to 'source/base/base_error.h') diff --git a/source/base/base_error.h b/source/base/base_error.h new file mode 100644 index 0000000..b2bb4c0 --- /dev/null +++ b/source/base/base_error.h @@ -0,0 +1,47 @@ +/* base library internal logging system */ +#ifndef BASE_ERROR_H +#define BASE_ERROR_H + +#define error_at(msg) \ + do \ + { \ + os_write(STDERR_FD, RED "[ERROR] ", LEN(RED "[ERROR] ")); \ + write_string(STDERR_FD, __FILE__); \ + write_string(STDERR_FD, ":"); \ + write_int(__LINE__); \ + write_string(STDERR_FD, " in "); \ + write_string(STDERR_FD, __func__); \ + write_string(STDERR_FD, ": "); \ + write_string(STDERR_FD, (msg)); \ + os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \ + } while (0) + +#define fatal(msg) \ + do \ + { \ + error_at(msg); \ + _exit(1); \ + } while (0) + +#define assert_msg(expr, msg) \ + do \ + { \ + if (!(expr)) \ + { \ + fatal(msg); \ + } \ + } while (0) + +#define warn(msg) \ + do \ + { \ + os_write(STDERR_FD, YELLOW "[WARN] ", LEN(YELLOW "[WARN] ")); \ + write_string(STDERR_FD, __FILE__); \ + write_string(STDERR_FD, ":"); \ + write_int(__LINE__); \ + write_string(STDERR_FD, ": "); \ + write_string(STDERR_FD, (msg)); \ + os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \ + } while (0) + +#endif /* BASE_ERROR_H */ -- cgit v1.3