libc-top-half/musl/src/malloc/mallocng/malloc_usable_size.c
raw| 1 | #include <stdlib.h> |
| 2 | #include "meta.h" |
| 3 | |
| 4 | size_t malloc_usable_size(void *p) |
| 5 | { |
| 6 | if (!p) return 0; |
| 7 | struct meta *g = get_meta(p); |
| 8 | int idx = get_slot_index(p); |
| 9 | size_t stride = get_stride(g); |
| 10 | unsigned char *start = g->mem->storage + stride*idx; |
| 11 | unsigned char *end = start + stride - IB; |
| 12 | return get_nominal_size(p, end); |
| 13 | } |