errors.c: implement mh_error_string

This commit is contained in:
Jakub Sztandera 2016-07-25 12:06:39 +01:00
parent 003bdf2f3c
commit 62384a9e0c

View file

@ -3,7 +3,7 @@
static const struct mh_error_desc { static const struct mh_error_desc {
int code; int code;
char *message; const char *message;
} mh_errordesc[] = { } mh_errordesc[] = {
{ MH_E_UNKNOWN_CODE, "unknown multihash code" }, { MH_E_UNKNOWN_CODE, "unknown multihash code" },
{ MH_E_TOO_SHORT, "multihash too short. must be > 3 bytes" }, { MH_E_TOO_SHORT, "multihash too short. must be > 3 bytes" },
@ -13,6 +13,11 @@ static const struct mh_error_desc {
}; };
const char *mh_error_string(mh_error code) { const char *mh_error_string(mh_error code) {
code += 1; unsigned int i = 0;
return ""; for (; i < sizeof(mh_errordesc); i++) {
if (mh_errordesc[i].code == code)
return mh_errordesc->message;
}
return "unknown error code";
} }