diff options
author | Determinant <[email protected]> | 2019-06-14 16:01:29 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-06-14 16:01:29 -0400 |
commit | 6c927588f78c663fded354fd696997d09fb5d697 (patch) | |
tree | d2367b60c81471a315d8f11fd107eb39b214e38b /src/util.cpp | |
parent | 2b23bd2e6b94edca0ef27d9560aedfc4459bd74b (diff) |
handle errors in C bindings
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp index f762b4c..874eb41 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -58,6 +58,31 @@ const char *TTY_COLOR_MAGENTA = "\x1b[35m"; const char *TTY_COLOR_CYAN = "\x1b[36m"; const char *TTY_COLOR_RESET = "\x1b[0m"; +extern "C" { + +SalticidaeCError salticidae_cerror_normal() { + SalticidaeCError res; + res.code = SALTI_NORMAL; + res.oscode = 0; + return res; +} + +SalticidaeCError salticidae_cerror_unknown() { + SalticidaeCError res; + res.code = SALTI_ERROR_UNKNOWN; + res.oscode = 0; + return res; +} + +const char *salticidae_strerror(int code) { + if (code < 0 || + code >= (int)(sizeof(SALTICIDAE_ERROR_STRINGS) / sizeof(const char *))) + return "invalid"; + return SALTICIDAE_ERROR_STRINGS[code]; +} + +} + void sec2tv(double t, struct timeval &tv) { tv.tv_sec = trunc(t); tv.tv_usec = trunc((t - tv.tv_sec) * 1e6); |