diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-05-11 13:22:59 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-05-11 13:22:59 +0200 |
commit | 74c9202e2a2347620cfe0459a2de060eebd7051b (patch) | |
tree | b5d5092b392f1ad4f4a1683b3932a3ed528cf170 /robot/errcatch.c | |
parent | 92f8dc33ab4517393f3b3db75715774d619585a8 (diff) |
[wip] error handling module
Diffstat (limited to 'robot/errcatch.c')
-rw-r--r-- | robot/errcatch.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/robot/errcatch.c b/robot/errcatch.c index 5b42bb4..a70a409 100644 --- a/robot/errcatch.c +++ b/robot/errcatch.c @@ -1,7 +1,34 @@ +#include <stdlib.h> +#include <string.h> + #include "errcatch.h" +w2_s_error g_w2_error_buffer[W2_ERROR_BUFFER_SIZE] = {}; +uint8_t g_w2_error_index = 0; +uint8_t g_w2_error_offset = 0; + void w2_errcatch_main() {} -void w2_errcatch_throw_msg(enum w2_e_errorcodes code, uint16_t length, const char *message) {} + +/** + * allocate and initialize error struct + * + * TODO: doesn't handle null pointers from calloc + */ +inline w2_s_error* w2_alloc_error(enum w2_e_errorcodes code, uint16_t length, const char *message) { + w2_s_error* error = calloc(sizeof(w2_s_error) + length, 1); + + memcpy(error, &(w2_s_error const){ .code = code, .message_length = length }, sizeof(w2_s_error)); + + // strncpy(error->message, message, length); + + return error; +} + +void w2_errcatch_throw_msg(enum w2_e_errorcodes code, uint16_t length, const char *message) { + w2_s_error error = *w2_alloc_error(code, length, message); + g_w2_error_buffer[g_w2_error_index] = error; + g_w2_error_index = (g_w2_error_index) & W2_ERROR_BUFFER_SIZE; +} void w2_errcatch_throw(enum w2_e_errorcodes code) { w2_errcatch_throw_msg(code, 0, ""); } |