summaryrefslogtreecommitdiff
path: root/src/xmalloc.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2021-11-15 19:37:48 +0000
committerPhil Jones <philj56@gmail.com>2021-11-15 19:37:48 +0000
commit49c7405b6a88e56bb69e12189adb719927343e07 (patch)
tree72c7691e746563cc1396c5b555659c813572c12e /src/xmalloc.c
parent108df42e561b7e81ba09a8c278a562129e651bb6 (diff)
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
Diffstat (limited to 'src/xmalloc.c')
-rw-r--r--src/xmalloc.c42
1 files changed, 42 insertions, 0 deletions
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 <stdio.h>
+#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);
+ }
+}