Browse Source

* simdb_error() : refactor

master
Alex 'AdUser' Z 4 years ago
parent
commit
086fcebc25
  1. 34
      src/database.c

34
src/database.c

@ -149,28 +149,20 @@ simdb_close(simdb_t *db) {
const char *
simdb_error(int error) {
if (error == SIMDB_SUCCESS) {
return "success";
} else if (error == SIMDB_ERR_SYSTEM) {
return strerror(errno);
} else if (error == SIMDB_ERR_OOM) {
return "can't allocate memory";
} else if (error == SIMDB_ERR_CORRUPTDB) {
return "database corrupted";
} else if (error == SIMDB_ERR_WRONGVERS) {
return "database version differs from library version";
} else if (error == SIMDB_ERR_READONLY) {
return "database opened in read-only mode";
} else if (error == SIMDB_ERR_NXRECORD) {
return "no such record in database";
} else if (error == SIMDB_ERR_USAGE) {
return "wrong parameters passed to finction";
} else if (error == SIMDB_ERR_SAMPLER) {
return "given file not an image, damaged or has unsupported format";
} else if (error == SIMDB_ERR_LOCK) {
return "can't add lock on database file";
const char *errstr = NULL;
switch (error) {
case SIMDB_SUCCESS : errstr = "success"; break;
case SIMDB_ERR_SYSTEM : errstr = strerror(errno); break;
case SIMDB_ERR_OOM : errstr = "can't allocate memory"; break;
case SIMDB_ERR_CORRUPTDB : errstr = "database corrupted"; break;
case SIMDB_ERR_WRONGVERS : errstr = "database version differs from library version"; break;
case SIMDB_ERR_READONLY : errstr = "database opened in read-only mode"; break;
case SIMDB_ERR_NXRECORD : errstr = "no such record in database"; break;
case SIMDB_ERR_USAGE : errstr = "wrong parameters passed to finction"; break;
case SIMDB_ERR_LOCK : errstr = "can't add lock on database file"; break;
default : errstr = "unknown error"; break;
}
return "unknown error";
return errstr;
}
int

Loading…
Cancel
Save