1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/* base library internal error checking system */
#ifndef BASE_ERROR_H
#define BASE_ERROR_H
internal inline void
write_int(s32 num)
{
if (num < 0)
{
write(STDERR_FILENO, "-", 1);
num = -num;
}
if (num >= 10) write_int(num / 10);
char digit = '0' + (num % 10);
write(STDERR_FILENO, &digit, 1);
}
#define error_at(msg) \
do { \
os_write(2, Red "[ERROR] " __FILE__ ":"); \
write_int(2, __LINE__); \
os_write(2, ":" __func__ ": " Reset); \
os_write(2, (msg)); \
os_write(2, "\n"); \
} while (0)
#define warn(msg) \
do { \
os_write(2, Yellow "[WARN] " __FILE__ ":"); \
write_int(2, __LINE__); \
os_write(2, ":" __func__ ": " Reset); \
os_write(2, (msg)); \
os_write(2, "\n"); \
} while (0)
#define assert_msg(expr, msg) \
do { \
if (!(expr)) { \
write_int(2, __LINE__); \
os_write(2, ":" __func__ ": " Reset); \
os_write(2, (msg)); \
os_write(2, "\n"); \
_exit(1); \
} \
} while (0)
#define test(expr) \
do { \
if ((expr) != 0) { \
os_write(2, "[FAILED] " __FILE__ ":"); \
write_int(2, __LINE__); \
os_write(2, ":" __func__ "\n"); \
_exit(1); \
} \
} while (0)
#endif /* BASE_ERROR_H */
|