summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-01-08 23:27:03 -0600
committersanine <sanine.not@pm.me>2023-01-08 23:27:03 -0600
commite7073c34d2ca92663d98bbb1912ad5f6e615e87f (patch)
tree9a4569ddf30041e35d15bf4b3d0592866e9b5d53 /src/util
parent38a71a0e8eb25418f6a0be23960a30de566dfb7c (diff)
add kai_allocmain
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