Browse Source

* simdb_error() : refactor

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

36
src/database.c

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

Loading…
Cancel
Save