This seems to be as close as I can get it to my style. I'd've wanted to also set Cpp11BracedListStyle[1] to Block, but that ended up misformatting some compound literals that included expressions with binary operators. I'm also unsure what is going on with the formatting of _Generic(). [1] https://clang.llvm.org/docs/ClangFormatStyleOptions.html#cpp11bracedliststyle
56 lines
972 B
C
56 lines
972 B
C
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "error.h"
|
|
|
|
char const *argv0;
|
|
|
|
[[noreturn]] void die(char const fmt[static 1], ...) {
|
|
fprintf(stderr, "%s: error: ", argv0);
|
|
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
vfprintf(stderr, fmt, args);
|
|
va_end(args);
|
|
|
|
fprintf(stderr, ": ");
|
|
|
|
perror(NULL);
|
|
|
|
exit(1);
|
|
}
|
|
|
|
[[noreturn]] void
|
|
panic_at(struct panic_location loc, char const fmt[static 1], ...) {
|
|
fprintf(
|
|
stderr, "%s: internal error in %s (%s, line %d): ", argv0, loc.function,
|
|
loc.file, loc.line
|
|
);
|
|
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
vfprintf(stderr, fmt, args);
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
abort();
|
|
}
|
|
|
|
[[noreturn]] void
|
|
panic_at_with_errno(struct panic_location loc, char const fmt[static 1], ...) {
|
|
fprintf(
|
|
stderr, "%s: internal error in %s (%s, line %d): ", argv0, loc.function,
|
|
loc.file, loc.line
|
|
);
|
|
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
vfprintf(stderr, fmt, args);
|
|
va_end(args);
|
|
|
|
perror(NULL);
|
|
|
|
abort();
|
|
}
|