2012-07-15 01:31:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* mm/mm_calloc.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2009-12-15 02:39:03 +01:00
|
|
|
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
|
2012-07-15 01:31:12 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2009-12-15 02:39:03 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2012-07-15 01:31:12 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-15 01:31:12 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2012-07-15 01:31:12 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-08 21:36:18 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <nuttx/mm.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-15 01:31:12 +02:00
|
|
|
/****************************************************************************
|
2009-12-15 02:39:03 +01:00
|
|
|
* Pre-processor Definitions
|
2012-07-15 01:31:12 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-15 01:31:12 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Global Functions
|
2012-07-15 01:31:12 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-08 21:36:18 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: mm_calloc
|
|
|
|
*
|
|
|
|
* Descripton:
|
|
|
|
* calloc calculates the size of the allocation and calls zalloc
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_MM_MULTIHEAP
|
|
|
|
FAR void *mm_calloc(FAR struct mm_heap_s *heap, size_t n, size_t elem_size)
|
|
|
|
{
|
|
|
|
FAR void *ret = NULL;
|
|
|
|
|
|
|
|
if (n > 0 && elem_size > 0)
|
|
|
|
{
|
|
|
|
ret = mm_zalloc(heap, n * elem_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-15 01:31:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: calloc
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Descripton:
|
2012-07-15 01:31:12 +02:00
|
|
|
* calloc calculates the size of the allocation and calls zalloc
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-08 21:36:18 +01:00
|
|
|
#if !defined(CONFIG_NUTTX_KERNEL) || !defined(__KERNEL__)
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR void *calloc(size_t n, size_t elem_size)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2013-03-08 21:36:18 +01:00
|
|
|
#ifdef CONFIG_MM_MULTIHEAP
|
|
|
|
return mm_calloc(&g_mmheap, n, elem_size);
|
|
|
|
#else
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR void *ret = NULL;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
if (n > 0 && elem_size > 0)
|
|
|
|
{
|
|
|
|
ret = zalloc(n * elem_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-03-08 21:36:18 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2013-03-08 21:36:18 +01:00
|
|
|
#endif
|