From 49c7405b6a88e56bb69e12189adb719927343e07 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Mon, 15 Nov 2021 19:37:48 +0000 Subject: Multiple smaller changes. - Remove the background image and libpng dependency - Add a prompt - Add xmalloc with out-of-memory handling - Add beginnings of a rofi-like run cache --- src/xmalloc.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/xmalloc.c (limited to 'src/xmalloc.c') diff --git a/src/xmalloc.c b/src/xmalloc.c new file mode 100644 index 0000000..8a08cb8 --- /dev/null +++ b/src/xmalloc.c @@ -0,0 +1,42 @@ +#include +#include "log.h" +#include "xmalloc.h" + +void *xmalloc(size_t size) +{ + void *ptr = malloc(size); + + if (ptr != NULL) { + log_debug("Allocated %zu bytes.\n", size); + return ptr; + } else { + fputs("Out of memory, exiting.", stderr); + exit(EXIT_FAILURE); + } +} + +void *xcalloc(size_t nmemb, size_t size) +{ + void *ptr = calloc(nmemb, size); + + if (ptr != NULL) { + log_debug("Allocated %zux%zu bytes.\n", nmemb, size); + return ptr; + } else { + fputs("Out of memory, exiting.", stderr); + exit(EXIT_FAILURE); + } +} + +void *xrealloc(void *ptr, size_t size) +{ + ptr = realloc(ptr, size); + + if (ptr != NULL) { + log_debug("Reallocated to %zu bytes.\n", size); + return ptr; + } else { + fputs("Out of memory, exiting.", stderr); + exit(EXIT_FAILURE); + } +} -- cgit v1.2.3