aboutsummaryrefslogtreecommitdiffstats
path: root/inc/malloc.h
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-22 12:31:46 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-22 12:42:48 +0100
commit29b8c1556bf456596c6c067d413b65b51e17724e (patch)
treeb225381d762af049e9174cdf1459db1f91c9589a /inc/malloc.h
downloadmalloc-29b8c1556bf456596c6c067d413b65b51e17724e.tar.gz
malloc-29b8c1556bf456596c6c067d413b65b51e17724e.zip
Initial scaffold: Makefile, stub malloc/free/realloc, test harness
Build system produces libft_malloc_$HOSTTYPE.so shared library with Libft (NOMALLOC=1) as dependency. Stub functions print their name and return NULL. Test runner compares system malloc vs LD_PRELOAD output using write(2) to avoid stdio interference.
Diffstat (limited to 'inc/malloc.h')
-rw-r--r--inc/malloc.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/inc/malloc.h b/inc/malloc.h
new file mode 100644
index 0000000..75ea6e9
--- /dev/null
+++ b/inc/malloc.h
@@ -0,0 +1,33 @@
+/**
+ * @file malloc.h
+ * @brief Public interface for the ft_malloc allocator.
+ *
+ * Declares malloc, free, realloc, and show_alloc_mem with the same
+ * prototypes as their libc counterparts so the library can be used
+ * as a drop-in replacement via LD_PRELOAD.
+ */
+
+#ifndef MALLOC_H
+#define MALLOC_H
+
+#include <stddef.h>
+
+/** @brief Release the memory block at @p ptr. */
+void free (void *ptr);
+
+/** @brief Allocate @p size bytes and return a pointer to them. */
+void *malloc (size_t size);
+
+/**
+ * @brief Resize the block at @p ptr to @p size bytes.
+ * @return Pointer to the (possibly moved) block, or NULL on failure.
+ */
+void *realloc (void *ptr, size_t size);
+
+/**
+ * @brief Print every allocated zone and block to stdout, sorted by
+ * ascending address.
+ */
+void show_alloc_mem (void);
+
+#endif