diff options
Diffstat (limited to 'myfind/ast_evaluation/memory.c')
| -rw-r--r-- | myfind/ast_evaluation/memory.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/myfind/ast_evaluation/memory.c b/myfind/ast_evaluation/memory.c new file mode 100644 index 0000000..fa32451 --- /dev/null +++ b/myfind/ast_evaluation/memory.c @@ -0,0 +1,36 @@ +#include "memory.h"
+
+#include <err.h>
+#include <stdlib.h>
+
+static inline void memory_exhausted(void)
+{
+ err(1, "Memory exhausted.");
+}
+
+void *my_malloc(size_t size)
+{
+ void *ptr = malloc(size);
+ if (size && !ptr)
+ memory_exhausted();
+
+ return ptr;
+}
+
+void *my_calloc(size_t nmemb, size_t size)
+{
+ void *ptr = calloc(nmemb, size);
+ if (size && nmemb && !ptr)
+ memory_exhausted();
+
+ return ptr;
+}
+
+void *my_reallocarray(void *ptr, size_t nmemb, size_t size)
+{
+ ptr = reallocarray(ptr, nmemb, size);
+ if (size && nmemb && !ptr)
+ memory_exhausted();
+
+ return ptr;
+}
|
