alloc.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <sys/mman.h>
  7. #ifdef L_calloc_dbg
  8. void *calloc_dbg(size_t num, size_t size, char *function, char *file,
  9. int line)
  10. {
  11. void *ptr;
  12. fprintf(stderr, "calloc of %ld bytes at %s @%s:%d = ",
  13. (long) (num * size), function, file, line);
  14. ptr = calloc(num, size);
  15. fprintf(stderr, "%p\n", ptr);
  16. return ptr;
  17. }
  18. #endif
  19. #ifdef L_malloc_dbg
  20. void *malloc_dbg(size_t len, char *function, char *file, int line)
  21. {
  22. void *result;
  23. fprintf(stderr, "malloc of %ld bytes at %s @%s:%d = ", (long) len,
  24. function, file, line);
  25. result = malloc(len);
  26. fprintf(stderr, "%p\n", result);
  27. return result;
  28. }
  29. #endif
  30. #ifdef L_free_dbg
  31. void free_dbg(void *ptr, char *function, char *file, int line)
  32. {
  33. fprintf(stderr, "free of %p at %s @%s:%d\n", ptr, function, file,
  34. line);
  35. free(ptr);
  36. }
  37. #endif
  38. #ifdef L_realloc_dbg
  39. void *realloc_dbg(void *ptr, size_t size, char *function, char *file, int line)
  40. {
  41. fprintf(stderr, "realloc of %p to %ld bytes at %s @%s;%d = ", ptr,
  42. (long)size, function, file, line);
  43. ptr = realloc(ptr, size);
  44. fprintf(stderr, "%p\n", ptr);
  45. return ptr;
  46. }
  47. #endif