diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-05-08 12:32:10 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-05-08 12:32:10 +0200 |
commit | 8f6d296a23675687177afd697cb28d195252466e (patch) | |
tree | d678a6cf14e5faa59c2b22459300e6d3477bb0ef | |
parent | 30e8e14cba8b278cbb15ff74d9447482e828b7aa (diff) |
Add a heap allocator
-rw-r--r-- | include/alloc.h | 1 | ||||
-rw-r--r-- | lib/alloc/heapalloc.c | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/include/alloc.h b/include/alloc.h index bcee92f..3074b27 100644 --- a/include/alloc.h +++ b/include/alloc.h @@ -22,6 +22,7 @@ typedef struct { [[nodiscard, gnu::returns_nonnull]] void *bufalloc(void *, size_t, size_t); [[nodiscard]] void *bufalloc_noterm(void *, size_t, size_t); +[[nodiscard]] void *heapalloc(void *, void *, size_t, size_t); [[_mlib_pure, _mlib_inline]] static inline arena diff --git a/lib/alloc/heapalloc.c b/lib/alloc/heapalloc.c new file mode 100644 index 0000000..0a698f0 --- /dev/null +++ b/lib/alloc/heapalloc.c @@ -0,0 +1,12 @@ +#include <stdlib.h> + +#include "alloc.h" + +void * +heapalloc(void *, void *ptr, size_t, size_t new) +{ + if (new > 0) + return realloc(ptr, new); + free(ptr); + return nullptr; +} |