musl-tcc/src/malloc/mallocng/malloc_usable_size.c

14 lines
321 B
C

#include <stdlib.h>
#include "meta.h"
size_t malloc_usable_size(void *p)
{
if (!p) return 0;
struct meta *g = get_meta(p);
int idx = get_slot_index(p);
size_t stride = get_stride(g);
unsigned char *start = g->mem->storage + stride*idx;
unsigned char *end = start + stride - IB;
return get_nominal_size(p, end);
}