aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 3d91753..c545961 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -64,3 +64,32 @@ void print_message(const char *file, const int line, enum Verbosity level, const
vfprintf(stderr, msg, args);
fputs("\n", stderr);
}
+
+void *smalloc_internal(const char *file, const int line, size_t size) {
+ void *r;
+ r = malloc(size);
+ if (!r)
+ error_out_of_memmory_internal(file, line);
+ return r;
+}
+
+void *scalloc_internal(const char *file, const int line, size_t nmemb, size_t size) {
+ void *r;
+ r = calloc(nmemb, size);
+ if (!r)
+ error_out_of_memmory_internal(file, line);
+ return r;
+}
+
+void *srealloc_internal(const char *file, const int line, void *ptr, size_t size) {
+ void *r;
+ r = realloc(ptr, size);
+ if (!r)
+ error_out_of_memmory_internal(file, line);
+ return r;
+}
+
+void error_out_of_memmory_internal(const char *file, const int line) {
+ print_message(file, line, V_DIE, "Memory allocation failed. Out of memory?");
+ abort();
+}