diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-11-01 00:17:33 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-11-01 00:17:33 +0100 |
commit | bb6b8ce9146d77cbea6c37eeac0fd1e760061036 (patch) | |
tree | c31b40aeb9fd06f7f4d65b987b46fb1620474d6d /src/util.c | |
parent | 48b7c4478488046e190f8c9e5fa6bd4ddfb1018e (diff) |
Introduce pcre2_bitch_and_die()
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..d20611f --- /dev/null +++ b/src/util.c @@ -0,0 +1,24 @@ +#include <stddef.h> +#include <stdlib.h> + +#include <errors.h> +#include <pcre2.h> + +#include "exitcodes.h" + +void +pcre2_bitch_and_die(int ec, const char *fmt) +{ + /* If we’ve gotten here, we don’t care about writing efficient code */ + ptrdiff_t bufsz = 512; + for (;;) { + char *buf = malloc(bufsz); + if (buf == nullptr) + cerr(EXIT_FATAL, "malloc:"); + if (pcre2_get_error_message(ec, buf, bufsz) == PCRE2_ERROR_NOMEMORY) { + free(buf); + bufsz *= 2; + } else + cerr(EXIT_FATAL, fmt, buf); + } +}
\ No newline at end of file |