From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- myfind/ast_evaluation/memory.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 myfind/ast_evaluation/memory.c (limited to 'myfind/ast_evaluation/memory.c') 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 +#include + +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; +} -- cgit v1.2.3