From 6c927588f78c663fded354fd696997d09fb5d697 Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 14 Jun 2019 16:01:29 -0400 Subject: handle errors in C bindings --- include/salticidae/util.h | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'include/salticidae/util.h') diff --git a/include/salticidae/util.h b/include/salticidae/util.h index 41f681c..007fcc4 100644 --- a/include/salticidae/util.h +++ b/include/salticidae/util.h @@ -22,11 +22,32 @@ * SOFTWARE. */ -#ifndef _SALTICIDAE_COMMON_H -#define _SALTICIDAE_COMMON_H +#ifndef _SALTICIDAE_UTIL_H +#define _SALTICIDAE_UTIL_H + +#include +#include +#include +#include "salticidae/config.h" + +typedef struct SalticidaeCError { + int code; + int oscode; +} SalticidaeCError; + +#ifdef __cplusplus +extern "C" { +#endif + +SalticidaeCError salticidae_cerror_normal(); +SalticidaeCError salticidae_cerror_unknown(); +const char *salticidae_strerror(int code); #ifdef __cplusplus +} +#endif +#ifdef __cplusplus #include #include #include @@ -34,11 +55,6 @@ #include #include #include -#include -#include -#include - -#include "salticidae/config.h" #include "salticidae/ref.h" namespace salticidae { @@ -66,7 +82,8 @@ enum SalticidaeErrorCode { SALTI_ERROR_OPTNAME_ALREADY_EXISTS, SALTI_ERROR_OPT_UNKNOWN_ACTION, SALTI_ERROR_CONFIG_LINE_TOO_LONG, - SALTI_ERROR_OPT_INVALID + SALTI_ERROR_OPT_INVALID, + SALTI_ERROR_UNKNOWN }; extern const char *SALTICIDAE_ERROR_STRINGS[]; @@ -95,6 +112,12 @@ class SalticidaeError: public std::exception { const char *what() const throw() override { return msg.c_str(); } int get_code() const { return code; } int get_oscode() const { return oscode; } + SalticidaeCError get_cerr() const { + SalticidaeCError res; + res.code = code; + res.oscode = oscode; + return res; + } }; @@ -366,7 +389,6 @@ class Config { }; } - #endif #endif -- cgit v1.2.3