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 --- include/malloc.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include') diff --git a/include/malloc.h b/include/malloc.h index 0e17817..956a5e5 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -241,6 +241,21 @@ void* aligned_alloc(size_t, size_t) #endif +#if defined(_GNU_SOURCE) && !defined(_PORTABLE_SOURCE) +/** + * 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*) + __GCC_ONLY(__attribute__((warn_unused_result))); +#endif + + #endif -- cgit v1.2.3-70-g09d2