minilib.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-02-23 Meco Man first version
  9. */
  10. #include <reent.h>
  11. #include <rtthread.h>
  12. #ifdef RT_USING_HEAP /* Memory routine */
  13. void *
  14. _malloc_r (struct _reent *ptr, size_t size)
  15. {
  16. void* result;
  17. result = (void*)rt_malloc (size);
  18. if (result == RT_NULL)
  19. {
  20. ptr->_errno = ENOMEM;
  21. }
  22. return result;
  23. }
  24. void *
  25. _realloc_r (struct _reent *ptr, void *old, size_t newlen)
  26. {
  27. void* result;
  28. result = (void*)rt_realloc (old, newlen);
  29. if (result == RT_NULL)
  30. {
  31. ptr->_errno = ENOMEM;
  32. }
  33. return result;
  34. }
  35. void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
  36. {
  37. void* result;
  38. result = (void*)rt_calloc (size, len);
  39. if (result == RT_NULL)
  40. {
  41. ptr->_errno = ENOMEM;
  42. }
  43. return result;
  44. }
  45. void
  46. _free_r (struct _reent *ptr, void *addr)
  47. {
  48. rt_free (addr);
  49. }
  50. #else
  51. void *
  52. _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
  53. {
  54. return RT_NULL;
  55. }
  56. #endif /*RT_USING_HEAP*/