summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/err.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/util/err.c b/util/err.c
index 62886c4..7a38017 100644
--- a/util/err.c
+++ b/util/err.c
@@ -8,3 +8,31 @@ static void err_print(LineNo line, LineNo col, const char *fmt, ...) {
vfprintf(stderr, fmt, args);
va_end(args);
}
+
+static void *err_malloc(size_t size) {
+ void *ret = malloc(size);
+ if (!ret) {
+ fprintf(stderr, "Error: Out of memory.\n");
+ abort();
+ }
+ return ret;
+}
+
+static void *err_calloc(size_t n, size_t size) {
+ void *ret = calloc(n, size);
+ if (!ret) {
+ fprintf(stderr, "Error: Out of memory.\n");
+ abort();
+ }
+ return ret;
+}
+
+static void *err_realloc(void *data, size_t new_size) {
+ void *ret = realloc(data, new_size);
+ if (!ret) {
+ fprintf(stderr, "Error: Out of memory.\n");
+ abort();
+ }
+ return ret;
+}
+