diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-12-24 19:04:37 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-12-24 19:06:23 -0500 |
| commit | cb336b312e7012dc05fe7d8ac1c0e924dbc6c840 (patch) | |
| tree | d2b8242e46452d12bfb1f7812f6965e64ddf9dfa /src/stdlib/fail.c | |
| parent | 649977aae7e5922f992cd69eb84da0a2db368580 (diff) | |
Shuffle dependencies around so header files aren't needed after tomo has
been compiled
Diffstat (limited to 'src/stdlib/fail.c')
| -rw-r--r-- | src/stdlib/fail.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/stdlib/fail.c b/src/stdlib/fail.c new file mode 100644 index 00000000..704624d3 --- /dev/null +++ b/src/stdlib/fail.c @@ -0,0 +1,38 @@ +// Failure functions +#include <errno.h> +#include <signal.h> +#include <stdio.h> // IWYU pragma: export + +#include "../util.h" +#include "fail.h" +#include "files.h" +#include "stacktrace.h" +#include "stdlib.h" +#include "text.h" +#include "util.h" + +public +_Noreturn void fail_text(Text_t message) { fail(message); } + +public +Text_t builtin_last_err() { return Text$from_str(strerror(errno)); } + +_Noreturn void fail_source(const char *filename, int start, int end, Text_t message) { + tomo_cleanup(); + fflush(stdout); + if (USE_COLOR) fputs("\x1b[31;7m ==================== ERROR ==================== \n\n\x1b[0;1m", stderr); + else fputs("==================== ERROR ====================\n\n", stderr); + print_stacktrace(stderr, 1); + fputs("\n", stderr); + if (USE_COLOR) fputs("\x1b[31;1m", stderr); + Text$print(stderr, message); + file_t *_file = (filename) ? load_file(filename) : NULL; + if ((filename) && _file) { + fputs("\n", stderr); + highlight_error(_file, _file->text + (start), _file->text + (end), "\x1b[31;1m", 1, USE_COLOR); + } + if (USE_COLOR) fputs("\x1b[m", stderr); + fflush(stderr); + raise(SIGABRT); + exit(1); +} |
