summaryrefslogtreecommitdiff
path: root/src/xmalloc.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2021-11-17 01:15:13 +0000
committerPhil Jones <philj56@gmail.com>2021-11-17 01:15:13 +0000
commit7562d7b539d8013376de2cff494231ba307f4ee1 (patch)
tree1eb4e8b28ed10da0e7a582cc4a38cfc37cef3ff8 /src/xmalloc.c
parent49c7405b6a88e56bb69e12189adb719927343e07 (diff)
Add sorting by run frequency.
This implements a rofi-like run cache. Other smaller changes include simplification of resize logic now that there's only one surface.
Diffstat (limited to 'src/xmalloc.c')
-rw-r--r--src/xmalloc.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/xmalloc.c b/src/xmalloc.c
index 8a08cb8..1c2a9dc 100644
--- a/src/xmalloc.c
+++ b/src/xmalloc.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <string.h>
#include "log.h"
#include "xmalloc.h"
@@ -7,10 +8,10 @@ void *xmalloc(size_t size)
void *ptr = malloc(size);
if (ptr != NULL) {
- log_debug("Allocated %zu bytes.\n", size);
+ //log_debug("Allocated %zu bytes.\n", size);
return ptr;
} else {
- fputs("Out of memory, exiting.", stderr);
+ log_error("Out of memory, exiting.\n");
exit(EXIT_FAILURE);
}
}
@@ -20,10 +21,10 @@ 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);
+ //log_debug("Allocated %zux%zu bytes.\n", nmemb, size);
return ptr;
} else {
- fputs("Out of memory, exiting.", stderr);
+ log_error("Out of memory, exiting.\n");
exit(EXIT_FAILURE);
}
}
@@ -33,10 +34,23 @@ void *xrealloc(void *ptr, size_t size)
ptr = realloc(ptr, size);
if (ptr != NULL) {
- log_debug("Reallocated to %zu bytes.\n", size);
+ //log_debug("Reallocated to %zu bytes.\n", size);
return ptr;
} else {
- fputs("Out of memory, exiting.", stderr);
+ log_error("Out of memory, exiting.\n");
+ exit(EXIT_FAILURE);
+ }
+}
+
+char *xstrdup(const char *s)
+{
+ char *ptr = strdup(s);
+
+ if (ptr != NULL) {
+ //log_debug("Allocated %zu bytes.\n", size);
+ return ptr;
+ } else {
+ log_error("Out of memory, exiting.\n");
exit(EXIT_FAILURE);
}
}