summaryrefslogtreecommitdiff
path: root/myfind/ast_evaluation/memory.c
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /myfind/ast_evaluation/memory.c
add: added projectsHEADmain
Diffstat (limited to 'myfind/ast_evaluation/memory.c')
-rw-r--r--myfind/ast_evaluation/memory.c36
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;
+}