summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/util.c11
-rw-r--r--src/util/util.h3
2 files changed, 14 insertions, 0 deletions
diff --git a/src/util/util.c b/src/util/util.c
index 00561b7..4f79870 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -62,3 +62,14 @@ size_t kai_text_to_longs(long *dest, const char *str, size_t count)
return result;
}
+
+
+void *kai_alloc(size_t size, const char *purpose)
+{
+ void *buf = malloc(size);
+ if (buf == NULL) {
+ fprintf(stderr, "[kalmia] ERROR: failed to allocated %ul-byte buffer for %s\n", size, purpose);
+ return NULL;
+ }
+ return buf;
+}
diff --git a/src/util/util.h b/src/util/util.h
index 0b6bc15..d5fa636 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -34,4 +34,7 @@ size_t kai_text_to_reals(ka_real_t *dest, const char *str, size_t count);
size_t kai_text_to_longs(long *dest, const char *str, size_t count);
+
+void *kai_alloc(size_t size, const char *purpose);
+
#endif