diff options
Diffstat (limited to 'nuttx/mm/mm_zalloc.c')
-rw-r--r-- | nuttx/mm/mm_zalloc.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/nuttx/mm/mm_zalloc.c b/nuttx/mm/mm_zalloc.c index 075777d0c..bf25aed84 100644 --- a/nuttx/mm/mm_zalloc.c +++ b/nuttx/mm/mm_zalloc.c @@ -37,8 +37,12 @@ * Included Files ****************************************************************************/ -#include "mm_environment.h" -#include "mm_internal.h" +#include <nuttx/config.h> + +#include <stdlib.h> +#include <string.h> + +#include <nuttx/mm.h> /**************************************************************************** * Pre-processor Definitions @@ -49,6 +53,27 @@ ****************************************************************************/ /**************************************************************************** + * Name: mm_zalloc + * + * Description: + * mm_zalloc calls mm_malloc, then zeroes out the allocated chunk. + * + ****************************************************************************/ + +#ifdef CONFIG_MM_MULTIHEAP +FAR void *mm_zalloc(FAR struct mm_heap_s *heap, size_t size) +{ + FAR void *alloc = mm_malloc(heap, size); + if (alloc) + { + memset(alloc, 0, size); + } + + return alloc; +} +#endif + +/**************************************************************************** * Name: zalloc * * Description: @@ -56,8 +81,12 @@ * ****************************************************************************/ +#if !defined(CONFIG_NUTTX_KERNEL) || !defined(__KERNEL__) FAR void *zalloc(size_t size) { +#ifdef CONFIG_MM_MULTIHEAP + return mm_zalloc(&g_mmheap, size); +#else FAR void *alloc = malloc(size); if (alloc) { @@ -65,4 +94,6 @@ FAR void *zalloc(size_t size) } return alloc; +#endif } +#endif |