liblash

Basic tools written and used by lash in c programming.
Info | Log | Files | Refs

commit c03c770d10ca08ce9af5e05bc374d4bccde9ff5b
parent 81d1f33a696dff16eb460f426af43da423947086
Author: lash <dev@holbrook.no>
Date:   Sun, 30 Mar 2025 13:36:14 +0100

Extend base reverse errors

Diffstat:
Msrc/llog/llog.h | 2++
Msrc/rerr/rerr.c | 31++++++++++++++++++++++++++++---
Msrc/rerr/rerr.h | 23++++++++++++++++++++---
3 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/src/llog/llog.h b/src/llog/llog.h @@ -1,7 +1,9 @@ #ifndef LLOG_H_ #define LLOG_H_ +#ifndef LLOG_LENGTH #define LLOG_LENGTH 1024 +#endif #ifndef LLOG_DEFAULT_NS #define LLOG_DEFAULT_NS "llog" diff --git a/src/rerr/rerr.c b/src/rerr/rerr.c @@ -3,21 +3,40 @@ #ifdef RERR static char** rerr[RERR_N_PFX + 1]; static const char* rerr_pfx[RERR_N_PFX + 1]; +#ifdef RERR_EXT +char *rerr_base[14] = { +#else char *rerr_base[3] = { +#endif "OK", - "FAIL", - "UNSUPPORTED", + "Failed", + "Not supported", +#ifdef RERR_EXT + "Initialization", + "No change", + "Not found", + "Read", + "Write", + "Memory", + "Incompatible", + "Encoding", + "Wrong byteorder", + "Value too large", + "Value too small", +#endif }; #endif void rerr_init(const char *coreprefix) { #ifdef RERR int i; + char *rerr_x; for (i = 1; i < RERR_N_PFX + 1; i++) { rerr[i] = 0x0; rerr_pfx[i] = 0x0; } + rerr[0] = rerr_base; rerr_pfx[0] = coreprefix; #endif @@ -41,7 +60,13 @@ static void splitcode(int code, short *k, char *v) { } static char *strv(short k, char v) { - return (char*)(*(rerr[k]+v)); + char **e; + + e = rerr[k]; + if (e == 0x0) { + return RERR_NOTFOUND_RESPONSE; + } + return (char*)(*(e+v)); } #endif diff --git a/src/rerr/rerr.h b/src/rerr/rerr.h @@ -1,14 +1,31 @@ #ifndef RERR_H_ #define RERR_H_ -#define ERR_OK 0x0 -#define ERR_FAIL 0x1 -#define ERR_UNSUPPORTED 0x2 +enum err_base_e { + ERR_OK, + ERR_FAIL, + ERR_SUPPORT, + ERR_INIT, + ERR_NOOP, + ERR_NOENT, + ERR_READ, + ERR_WRITE, + ERR_MEM, + ERR_COMPAT, + ERR_ENCODING, + ERR_BYTEORDER, + ERR_OVERFLOW, + ERR_UNDERFLOW, +}; #ifndef RERR_N_PFX #define RERR_N_PFX 0 #endif +#ifndef RERR_NOTFOUND_RESPONSE +#define RERR_NOTFOUND_RESPONSE "(unregistered)" +#endif + void rerr_init(const char *coreprefix); void rerr_register(int pfx, char *label, void *start); char* rerrstr(int code, char *buf);