#include #include #include #include #include "exception_t.h" exception_t* exception_init() { exception_t *e = (exception_t*) malloc(sizeof(exception_t)); e->type = NO_ERROR; e->msg = malloc(CHAR_MAX); return e; } void exception_free(exception_t *e) { free(e->msg); free(e); } int exception_null(const exception_t *e) { return e->type == NO_ERROR; } char* exception_prestr(const exception_t *e) { switch(e->type) { case NO_ERROR: return "No error\n"; case NO_FILE: return "No file found"; case XML_FILE_MISSING: return "XML file missing"; case XML_READ_FILE_FAIL: return "XML file reading failed"; case MD5SUM_GEN_FAIL: return "MD5sum generation failed"; case MD5SUM_VERIFY_FAIL: return "MD5sum verification failed"; } } char* exception_str(const exception_t *e, char* msg) { if (e->type != NO_ERROR) sprintf(msg, "%s: %s\n", exception_prestr(e), e->msg); else sprintf(msg, "%s\n", exception_prestr(e)); return msg; }