diff options
author | 3gg <3gg@shellblade.net> | 2023-06-17 20:21:58 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2023-06-17 20:21:58 -0700 |
commit | 08ec3a7a1fdb16cbb52b05f934bd001ca38bd991 (patch) | |
tree | 664da276c93ae301c0bac038cd011afda6396ac3 | |
parent | 2f8ff39a8d95b95288875d92abb74b1428713906 (diff) |
Add error library.
-rw-r--r-- | error/CMakeLists.txt | 14 | ||||
-rw-r--r-- | error/include/error.h | 22 | ||||
-rw-r--r-- | error/src/error.c | 5 |
3 files changed, 41 insertions, 0 deletions
diff --git a/error/CMakeLists.txt b/error/CMakeLists.txt new file mode 100644 index 0000000..e47a1f9 --- /dev/null +++ b/error/CMakeLists.txt | |||
@@ -0,0 +1,14 @@ | |||
1 | cmake_minimum_required(VERSION 3.0) | ||
2 | |||
3 | project(error) | ||
4 | |||
5 | add_library(error | ||
6 | src/error.c) | ||
7 | |||
8 | target_include_directories(error PUBLIC | ||
9 | include) | ||
10 | |||
11 | target_link_libraries(error | ||
12 | cstring) | ||
13 | |||
14 | target_compile_options(error PRIVATE -Wall -Wextra) | ||
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 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <cstring.h> | ||
4 | #include <stdio.h> | ||
5 | |||
6 | /// Get the last error. | ||
7 | const char* get_error(void); | ||
8 | |||
9 | extern xlstring gfx_error; | ||
10 | |||
11 | /// Set the last error. | ||
12 | #define set_error(...) \ | ||
13 | gfx_error.length = snprintf(gfx_error.str, xlstring_size, __VA_ARGS__) | ||
14 | |||
15 | /// Prepend an error to the last error. | ||
16 | #define prepend_error(...) \ | ||
17 | { \ | ||
18 | xlstring head; \ | ||
19 | head.length = snprintf(head.str, xlstring_size, __VA_ARGS__); \ | ||
20 | xlstring_append(&head, xlstring_make(": ")); \ | ||
21 | gfx_error = xlstring_concat(head, gfx_error); \ | ||
22 | } | ||
diff --git a/error/src/error.c b/error/src/error.c new file mode 100644 index 0000000..ccd850d --- /dev/null +++ b/error/src/error.c | |||
@@ -0,0 +1,5 @@ | |||
1 | #include "error.h" | ||
2 | |||
3 | xlstring gfx_error; | ||
4 | |||
5 | const char* get_error(void) { return xlstring_cstr(&gfx_error); } | ||