aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-02-25 15:11:23 -0800
committer3gg <3gg@shellblade.net>2024-02-25 15:11:23 -0800
commitd666c271bec412d700298200dbff22102c2bdd63 (patch)
tree8193d7f383d839ecd89dbd81a7e475b15fbf81b5
parentf24912296c473ac15c12e65c97007fe3ece87dfa (diff)
Simpler error logging API.
-rw-r--r--error/include/error.h24
-rw-r--r--error/src/error.c4
2 files changed, 14 insertions, 14 deletions
diff --git a/error/include/error.h b/error/include/error.h
index 92c06ff..23df5f3 100644
--- a/error/include/error.h
+++ b/error/include/error.h
@@ -6,17 +6,17 @@
6/// Get the last error. 6/// Get the last error.
7const char* get_error(void); 7const char* get_error(void);
8 8
9extern xlstring gfx_error; 9extern xlstring g_error;
10 10
11/// Set the last error. 11/// Log an error.
12#define set_error(...) \ 12#define log_error(...) \
13 gfx_error.length = snprintf(gfx_error.str, xlstring_size, __VA_ARGS__) 13 { \
14 14 if (g_error.length == 0) { \
15/// Prepend an error to the last error. 15 g_error.length = snprintf(g_error.str, xlstring_size, __VA_ARGS__); \
16#define prepend_error(...) \ 16 } else { \
17 { \ 17 xlstring head; \
18 xlstring head; \ 18 head.length = snprintf(head.str, xlstring_size, __VA_ARGS__); \
19 head.length = snprintf(head.str, xlstring_size, __VA_ARGS__); \ 19 xlstring_append(&head, xlstring_make(": ")); \
20 xlstring_append(&head, xlstring_make(": ")); \ 20 g_error = xlstring_concat(head, g_error); \
21 gfx_error = xlstring_concat(head, gfx_error); \ 21 } \
22 } 22 }
diff --git a/error/src/error.c b/error/src/error.c
index ccd850d..81fb056 100644
--- a/error/src/error.c
+++ b/error/src/error.c
@@ -1,5 +1,5 @@
1#include "error.h" 1#include "error.h"
2 2
3xlstring gfx_error; 3xlstring g_error;
4 4
5const char* get_error(void) { return xlstring_cstr(&gfx_error); } 5const char* get_error(void) { return xlstring_cstr(&g_error); }