aboutsummaryrefslogtreecommitdiff
path: root/src/malloc/mallocng/malloc_usable_size.c
blob: 19f4ab401b44331e9c553404725a7d673e7ec272 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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);
}


#ifdef TEST
int
main(void) {
	return 0;
}
#endif