summaryrefslogtreecommitdiff
path: root/components/libc/compilers
diff options
context:
space:
mode:
authorMeco Jianting Man <[email protected]>2021-03-01 07:25:48 -0600
committerGitHub <[email protected]>2021-03-01 07:25:48 -0600
commitfab4c5ebb13fd92273de8727c0f18d53716295ff (patch)
treeb8f309bfe504c942560ea56d90c6f349e80c4c56 /components/libc/compilers
parent8932ffdb96b793031bbc71bb3bd23202939fcb2c (diff)
parent339ebf3c16e4c067f4ddfb7880709a534d41cf53 (diff)
Merge pull request #22 from RT-Thread/master
pr
Diffstat (limited to 'components/libc/compilers')
-rw-r--r--components/libc/compilers/newlib/minilib.c54
-rw-r--r--components/libc/compilers/newlib/syscalls.c17
2 files changed, 61 insertions, 10 deletions
diff --git a/components/libc/compilers/newlib/minilib.c b/components/libc/compilers/newlib/minilib.c
index 2d07eabe5a..ca1bea0f91 100644
--- a/components/libc/compilers/newlib/minilib.c
+++ b/components/libc/compilers/newlib/minilib.c
@@ -11,8 +11,58 @@
#include <reent.h>
#include <rtthread.h>
-void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
+#ifdef RT_USING_HEAP /* Memory routine */
+void *
+_malloc_r (struct _reent *ptr, size_t size)
+{
+ void* result;
+
+ result = (void*)rt_malloc (size);
+ if (result == RT_NULL)
+ {
+ ptr->_errno = ENOMEM;
+ }
+
+ return result;
+}
+
+void *
+_realloc_r (struct _reent *ptr, void *old, size_t newlen)
+{
+ void* result;
+
+ result = (void*)rt_realloc (old, newlen);
+ if (result == RT_NULL)
+ {
+ ptr->_errno = ENOMEM;
+ }
+
+ return result;
+}
+
+void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
+{
+ void* result;
+
+ result = (void*)rt_calloc (size, len);
+ if (result == RT_NULL)
+ {
+ ptr->_errno = ENOMEM;
+ }
+
+ return result;
+}
+
+void
+_free_r (struct _reent *ptr, void *addr)
+{
+ rt_free (addr);
+}
+
+#else
+void *
+_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{
- /* no use this routine to get memory */
return RT_NULL;
}
+#endif /*RT_USING_HEAP*/
diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c
index 949d8a61de..e54d7583cb 100644
--- a/components/libc/compilers/newlib/syscalls.c
+++ b/components/libc/compilers/newlib/syscalls.c
@@ -189,13 +189,6 @@ _rename_r(struct _reent *ptr, const char *old, const char *new)
#endif
}
-void *
-_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
-{
- /* no use this routine to get memory */
- return RT_NULL;
-}
-
int
_stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{
@@ -258,7 +251,7 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
#endif
}
-/* Memory routine */
+#ifdef RT_USING_HEAP /* Memory routine */
void *
_malloc_r (struct _reent *ptr, size_t size)
{
@@ -306,6 +299,14 @@ _free_r (struct _reent *ptr, void *addr)
rt_free (addr);
}
+#else
+void *
+_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
+{
+ return RT_NULL;
+}
+#endif /*RT_USING_HEAP*/
+
/* for exit() and abort() */
__attribute__ ((noreturn)) void
_exit (int status)