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/CMakeLists.txt | 14 ++++++++++++++ error/include/error.h | 22 ++++++++++++++++++++++ error/src/error.c | 5 +++++ 3 files changed, 41 insertions(+) create mode 100644 error/CMakeLists.txt create mode 100644 error/include/error.h create mode 100644 error/src/error.c (limited to 'error') 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 @@ +cmake_minimum_required(VERSION 3.0) + +project(error) + +add_library(error + src/error.c) + +target_include_directories(error PUBLIC + include) + +target_link_libraries(error + cstring) + +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 @@ +#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); \ + } 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 @@ +#include "error.h" + +xlstring gfx_error; + +const char* get_error(void) { return xlstring_cstr(&gfx_error); } -- cgit v1.2.3