aboutsummaryrefslogtreecommitdiff
path: root/error
diff options
context:
space:
mode:
Diffstat (limited to 'error')
-rw-r--r--error/CMakeLists.txt14
-rw-r--r--error/include/error.h22
-rw-r--r--error/src/error.c5
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 @@
1cmake_minimum_required(VERSION 3.0)
2
3project(error)
4
5add_library(error
6 src/error.c)
7
8target_include_directories(error PUBLIC
9 include)
10
11target_link_libraries(error
12 cstring)
13
14target_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.
7const char* get_error(void);
8
9extern 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
3xlstring gfx_error;
4
5const char* get_error(void) { return xlstring_cstr(&gfx_error); }