#include #include #include #include "Error.h" void eInitError(Error* e, const char* path, int line, int codeLine, const char* format, ...) { va_list args; va_start(args, format); eInitErrorV(e, path, line, codeLine, format, args); va_end(args); } void eInitErrorV(Error* e, const char* path, int line, int codeLine, const char* format, va_list ap) { e->line = line; e->codeLine = codeLine; vsnprintf(e->message, sizeof(e->message), format, ap); snprintf(e->paths, sizeof(e->paths), "%s", path); } void eInitSuccess(Error* e) { e->line = -1; e->message[0] = '\0'; e->paths[0] = '\0'; } void eAddPath(Error* e, const char* path) { char buffer[sizeof(e->paths)]; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-truncation" if(e->paths[0] == '\0') { snprintf(buffer, sizeof(buffer), "%s", path); } else { snprintf(buffer, sizeof(buffer), "%s -> %s", path, e->paths); } #pragma GCC diagnostic pop memcpy(e->paths, buffer, sizeof(buffer)); } bool eHasError(const Error* e) { return e->line >= 0; }