From 00c88659104ce423959151ff6f3f96f6537a6d68 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 14 Dec 2023 18:08:16 -0500 Subject: testing --- src/lib.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/lib.c (limited to 'src/lib.c') diff --git a/src/lib.c b/src/lib.c new file mode 100644 index 0000000..7f077ba --- /dev/null +++ b/src/lib.c @@ -0,0 +1,44 @@ +#include "lib.h" + +#include +#include +#include + +__attribute__((__noreturn__)) +static void die() { + exit(1); +} + +void error_and_die(char *format, ...) { + va_list list; + va_start(list, format); + + vfprintf(stderr, format, list); + + die(); +} + +__attribute__((__noreturn__, format(printf, 1, 2))) +void perror_and_die(char *format, ...) { + va_list list; + va_start(list, format); + + vfprintf(stderr, format, list); + perror(": "); + + die(); +} + +void *xalloc(size_t amount) { + void *res = malloc(amount); + if (res == NULL) + error_and_die("failed to allocate memory"); + return res; +} + +void *xrealloc(void *ptr, size_t amount) { + void *res = realloc(ptr, amount); + if (res == NULL) + error_and_die("failed to allocate memory"); + return res; +} -- cgit v1.2.3-freya