1
0

minilib.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2021, 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. #include <sys/errno.h>
  14. void * _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 * _realloc_r (struct _reent *ptr, void *old, size_t newlen)
  25. {
  26. void* result;
  27. result = (void*)rt_realloc (old, newlen);
  28. if (result == RT_NULL)
  29. {
  30. ptr->_errno = ENOMEM;
  31. }
  32. return result;
  33. }
  34. void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
  35. {
  36. void* result;
  37. result = (void*)rt_calloc (size, len);
  38. if (result == RT_NULL)
  39. {
  40. ptr->_errno = ENOMEM;
  41. }
  42. return result;
  43. }
  44. void _free_r (struct _reent *ptr, void *addr)
  45. {
  46. rt_free (addr);
  47. }
  48. #else
  49. void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
  50. {
  51. return RT_NULL;
  52. }
  53. #endif /*RT_USING_HEAP*/