You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 line
529B

  1. /*
  2. * This file is a part of SMalloc.
  3. * SMalloc is MIT licensed.
  4. * Copyright (c) 2017 Andrey Rys.
  5. */
  6. #include "smalloc_i.h"
  7. size_t sm_szalloc_pool(struct smalloc_pool *spool, const void *p)
  8. {
  9. struct smalloc_hdr *shdr;
  10. if (!smalloc_verify_pool(spool)) {
  11. errno = EINVAL;
  12. return ((size_t)-1);
  13. }
  14. if (!p) return 0;
  15. shdr = USER_TO_HEADER(p);
  16. if (smalloc_is_alloc(spool, shdr)) return shdr->usz;
  17. smalloc_UB(spool, p);
  18. return 0;
  19. }
  20. size_t sm_szalloc(const void *p)
  21. {
  22. return sm_szalloc_pool(&smalloc_curr_pool, p);
  23. }