errors.c: implement mh_error_string
This commit is contained in:
parent
003bdf2f3c
commit
62384a9e0c
1 changed files with 8 additions and 3 deletions
11
errors.c
11
errors.c
|
@ -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";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue