bsd-malloc.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2017 Darren Tucker (dtucker at zip com au).
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "config.h"
  17. #undef malloc
  18. #undef calloc
  19. #undef realloc
  20. #include <sys/types.h>
  21. #include <stdlib.h>
  22. #if defined(HAVE_MALLOC) && HAVE_MALLOC == 0
  23. void *
  24. rpl_malloc(size_t size)
  25. {
  26. if (size == 0)
  27. size = 1;
  28. return malloc(size);
  29. }
  30. #endif
  31. #if defined(HAVE_CALLOC) && HAVE_CALLOC == 0
  32. void *
  33. rpl_calloc(size_t nmemb, size_t size)
  34. {
  35. if (nmemb == 0)
  36. nmemb = 1;
  37. if (size == 0)
  38. size = 1;
  39. return calloc(nmemb, size);
  40. }
  41. #endif
  42. #if defined (HAVE_REALLOC) && HAVE_REALLOC == 0
  43. void *
  44. rpl_realloc(void *ptr, size_t size)
  45. {
  46. if (size == 0)
  47. size = 1;
  48. if (ptr == 0)
  49. return malloc(size);
  50. return realloc(ptr, size);
  51. }
  52. #endif