blob: 69bd600b7b0072386585f12864069ecce80f2045 [file] [log] [blame]
xiaohu.huangbf62d7b2023-07-18 18:02:43 +08001/*
2 * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#include <stdlib.h>
8#include <string.h>
9#include <stdint.h>
10#include "aml_calloc.h"
11#include <FreeRTOS.h>
12
13void *calloc(size_t nmemb, size_t size)
14{
15 void *ptr;
16 int nb;
17
18 nb = sizeof(size_t) * 4;
19 if (size >= SIZE_MAX >> nb || nmemb >= SIZE_MAX >> nb)
20 return NULL;
21
22 size *= nmemb;
23 ptr = pvPortMalloc(size);
24 if (ptr)
25 memset(ptr, 0, size);
26
27 return ptr;
28}