From 3305a21cd0fa4e3b43b1a4495dfc711297ac0cc4 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 30 Aug 2015 19:46:52 +0200 Subject: add malloc_usable_size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/malloc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/malloc.c b/src/malloc.c index f7a2e95..e09cc85 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -307,3 +307,18 @@ void* aligned_alloc(size_t boundary, size_t size) return memalign(boundary, size); } + +/** + * This function returns the allocation size of + * a memory segment. + * + * `p = malloc(n), malloc_usable_size(p)` will return `n`. + * + * @param segment The memory segment. + * @return The size of the memory segment, 0 if `segment` is `NULL`. + */ +size_t malloc_usable_size(void* segment) +{ + return allocsize(segment); +} + -- cgit v1.2.3-70-g09d2