From 48738e864fad3c53437e5cf80d9d9b8a13d798ab Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Tue, 30 Nov 2010 06:58:37 +0000 Subject: [PATCH] set ENOMEM when malloc failed. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1156 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/libc/newlib/syscalls.c | 40 +++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/components/libc/newlib/syscalls.c b/components/libc/newlib/syscalls.c index 9960be97ab..9254cc7cea 100644 --- a/components/libc/newlib/syscalls.c +++ b/components/libc/newlib/syscalls.c @@ -195,18 +195,42 @@ _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp) void * _malloc_r (struct _reent *ptr, size_t size) { - return (void*)rt_malloc (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) { - return (void*)rt_realloc (old, 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) { - return (void*)rt_calloc (size, len); + void* result; + + result = (void*)rt_calloc (size, len); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; } void @@ -215,19 +239,9 @@ _free_r (struct _reent *ptr, void *addr) rt_free (addr); } -#if 0 -void __assert(const char *file, int line, const char *failedexpr) -{ - rt_kprintf("assertion \"%s\" failed: file \"%s\", line %d\n", - failedexpr, file, line); - RT_ASSERT(0); -} -#endif - void _exit (int status) { rt_kprintf("thread:%s exit with %d\n", rt_thread_self()->name, status); RT_ASSERT(0); } -