From 08ec3a7a1fdb16cbb52b05f934bd001ca38bd991 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 17 Jun 2023 20:21:58 -0700 Subject: Add error library. --- error/include/error.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 error/include/error.h (limited to 'error/include/error.h') diff --git a/error/include/error.h b/error/include/error.h new file mode 100644 index 0000000..92c06ff --- /dev/null +++ b/error/include/error.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +/// Get the last error. +const char* get_error(void); + +extern xlstring gfx_error; + +/// Set the last error. +#define set_error(...) \ + gfx_error.length = snprintf(gfx_error.str, xlstring_size, __VA_ARGS__) + +/// Prepend an error to the last error. +#define prepend_error(...) \ + { \ + xlstring head; \ + head.length = snprintf(head.str, xlstring_size, __VA_ARGS__); \ + xlstring_append(&head, xlstring_make(": ")); \ + gfx_error = xlstring_concat(head, gfx_error); \ + } -- cgit v1.2.3