summaryrefslogtreecommitdiff
path: root/source/base/base_error.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/base/base_error.h')
-rw-r--r--source/base/base_error.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/source/base/base_error.h b/source/base/base_error.h
new file mode 100644
index 0000000..4bf84fc
--- /dev/null
+++ b/source/base/base_error.h
@@ -0,0 +1,43 @@
1/* base library internal error checking 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 error_at(msg); \
22 _exit(1); \
23 } while (0)
24
25#define assert_msg(expr, msg) \
26 do \
27 { \
28 if (!(expr)) _fatal(msg); \
29 } while (0)
30
31#define warn(msg) \
32 do \
33 { \
34 os_write(STDERR_FD, Yellow "[WARN] ", Len(Yellow "[WARN] ")); \
35 write_string(STDERR_FD, __FILE__); \
36 write_string(STDERR_FD, ":"); \
37 write_int(__LINE__); \
38 write_string(STDERR_FD, ": "); \
39 write_string(STDERR_FD, (msg)); \
40 os_write(STDERR_FD, Reset "\n", Len(Reset "\n")); \
41 } while (0)
42
43#endif /* BASE_ERROR_H */