diff options
| author | nasr <nsrddyn@gmail.com> | 2026-04-16 17:10:02 +0200 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-04-16 17:10:02 +0200 |
| commit | 8ea6a3c8621287d11296b8300029f32a27743d9a (patch) | |
| tree | cd12aa5fcd3e058fa74b45705c7b82524658d444 /source/base/base_error.h | |
| parent | f430bfe8f71430032bec689bf0bbdc94ac409c22 (diff) | |
feature(checkpoint): checkpoint cleaning up base library
Diffstat (limited to 'source/base/base_error.h')
| -rw-r--r-- | source/base/base_error.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/source/base/base_error.h b/source/base/base_error.h new file mode 100644 index 0000000..e9f52b7 --- /dev/null +++ b/source/base/base_error.h | |||
| @@ -0,0 +1,66 @@ | |||
| 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 | write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ | ||
| 8 | write_int(STDERR_FD, __LINE__); \ | ||
| 9 | write_string(STDERR_FD, ":" __func__ ": " Reset); \ | ||
| 10 | write_string(STDERR_FD, (msg)); \ | ||
| 11 | write_string(STDERR_FD, "\n"); \ | ||
| 12 | } while (0) | ||
| 13 | |||
| 14 | #define warn(msg) \ | ||
| 15 | do { \ | ||
| 16 | write_string(STDERR_FD, Yellow "[WARN] " __FILE__ ":"); \ | ||
| 17 | write_int(STDERR_FD, __LINE__); \ | ||
| 18 | write_string(STDERR_FD, ":" __func__ ": " Reset); \ | ||
| 19 | write_string(STDERR_FD, (msg)); \ | ||
| 20 | write_string(STDERR_FD, "\n"); \ | ||
| 21 | } while (0) | ||
| 22 | |||
| 23 | #define assert_msg(expr, msg) \ | ||
| 24 | do { \ | ||
| 25 | if (!(expr)) { \ | ||
| 26 | write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ | ||
| 27 | write_int(STDERR_FD, __LINE__); \ | ||
| 28 | write_string(STDERR_FD, ":" __func__ ": " Reset); \ | ||
| 29 | write_string(STDERR_FD, (msg)); \ | ||
| 30 | write_string(STDERR_FD, "\n"); \ | ||
| 31 | _exit(1); \ | ||
| 32 | } \ | ||
| 33 | } while (0) | ||
| 34 | |||
| 35 | #define show \ | ||
| 36 | do { \ | ||
| 37 | write_string(STDOUT_FD, __FILE__ ":"); \ | ||
| 38 | write_int(STDOUT_FD, __LINE__); \ | ||
| 39 | write_string(STDOUT_FD, ":" __func__ "\n"); \ | ||
| 40 | } while (0) | ||
| 41 | |||
| 42 | #define test(expr) \ | ||
| 43 | do { \ | ||
| 44 | if ((expr) != 0) { \ | ||
| 45 | write_string(STDERR_FD, "[FAILED] " __FILE__ ":"); \ | ||
| 46 | write_int(STDERR_FD, __LINE__); \ | ||
| 47 | write_string(STDERR_FD, ":" __func__ "\n"); \ | ||
| 48 | _exit(1); \ | ||
| 49 | } \ | ||
| 50 | } while (0) | ||
| 51 | |||
| 52 | #define verify(expr) \ | ||
| 53 | do { \ | ||
| 54 | if ((expr) != 0) { \ | ||
| 55 | write_string(STDERR_FD, Red "[ERROR] " __FILE__ ":"); \ | ||
| 56 | write_int(STDERR_FD, __LINE__); \ | ||
| 57 | write_string(STDERR_FD, ":" __func__ "\n" Reset); \ | ||
| 58 | _exit(1); \ | ||
| 59 | } else { \ | ||
| 60 | write_string(STDERR_FD, Green "[OK] " __FILE__ ":"); \ | ||
| 61 | write_int(STDERR_FD, __LINE__); \ | ||
| 62 | write_string(STDERR_FD, ":" __func__ "\n" Reset); \ | ||
| 63 | } \ | ||
| 64 | } while (0) | ||
| 65 | |||
| 66 | #endif /* BASE_ERROR_H */ | ||
