123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include <stdarg.h>
- #include <stdio.h>
- #include <string.h>
- #include "Error.h"
- void eInitError(Error* e, const char* path, int line, const char* format, ...) {
- va_list args;
- va_start(args, format);
- eInitErrorV(e, path, line, format, args);
- va_end(args);
- }
- void eInitErrorV(Error* e, const char* path, int line, const char* format,
- va_list ap) {
- e->line = line;
- 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;
- }
|