summaryrefslogtreecommitdiff
path: root/source/base/base_error.h
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-04-13 15:33:05 +0200
committernasr <nsrddyn@gmail.com>2026-04-13 15:36:24 +0200
commit9d09d66a273f68fae7efb71504bf40c664b91983 (patch)
tree41a46c52a01338bf22d5f3ebdf0bb27dc3d33cc1 /source/base/base_error.h
feature(main): init
feature(main): init feature(main): init feature(main): init
Diffstat (limited to 'source/base/base_error.h')
-rw-r--r--source/base/base_error.h47
1 files changed, 47 insertions, 0 deletions
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 @@
1/* base library internal logging system */
2#ifndef BASE_ERROR_H
3#define BASE_ERROR_H
4
5#define error_at(msg) \
6 do \
7 { \
8 os_write(STDERR_FD, RED "[ERROR] ", LEN(RED "[ERROR] ")); \
9 write_string(STDERR_FD, __FILE__); \
10 write_string(STDERR_FD, ":"); \
11 write_int(__LINE__); \
12 write_string(STDERR_FD, " in "); \
13 write_string(STDERR_FD, __func__); \
14 write_string(STDERR_FD, ": "); \
15 write_string(STDERR_FD, (msg)); \
16 os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \
17 } while (0)
18
19#define fatal(msg) \
20 do \
21 { \
22 error_at(msg); \
23 _exit(1); \
24 } while (0)
25
26#define assert_msg(expr, msg) \
27 do \
28 { \
29 if (!(expr)) \
30 { \
31 fatal(msg); \
32 } \
33 } while (0)
34
35#define warn(msg) \
36 do \
37 { \
38 os_write(STDERR_FD, YELLOW "[WARN] ", LEN(YELLOW "[WARN] ")); \
39 write_string(STDERR_FD, __FILE__); \
40 write_string(STDERR_FD, ":"); \
41 write_int(__LINE__); \
42 write_string(STDERR_FD, ": "); \
43 write_string(STDERR_FD, (msg)); \
44 os_write(STDERR_FD, RESET "\n", LEN(RESET "\n")); \
45 } while (0)
46
47#endif /* BASE_ERROR_H */