aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/util.h2
-rw-r--r--src/util.c22
2 files changed, 24 insertions, 0 deletions
diff --git a/include/util.h b/include/util.h
index bdf260e..5a5a819 100644
--- a/include/util.h
+++ b/include/util.h
@@ -10,5 +10,7 @@ enum exit_status {
};
void *must_malloc(size_t size);
+void *must_calloc(size_t nmemb, size_t size);
+void *must_realloc(void *ptr, size_t size);
#endif
diff --git a/src/util.c b/src/util.c
index 9b79ac7..5918968 100644
--- a/src/util.c
+++ b/src/util.c
@@ -11,3 +11,25 @@ must_malloc(size_t size)
exit(EXIT_ABNORMAL);
}
}
+
+void *
+must_calloc(size_t nmemb, size_t size)
+{
+ void *ret = calloc(nmemb, size);
+ if (ret == NULL) {
+ fprintf(stderr, "out of memory\n");
+ exit(EXIT_ABNORMAL);
+ }
+ return ret;
+}
+
+void *
+must_realloc(void *ptr, size_t size)
+{
+ void *ret = realloc(ptr, size);
+ if (ret == NULL) {
+ fprintf(stderr, "out of memory\n");
+ exit(EXIT_ABNORMAL);
+ }
+ return ret;
+}