1a8e1175bSopenharmony_ci/* mbedtls_config.h modifier that forces calloc(0) to return NULL.
2a8e1175bSopenharmony_ci * Used for testing.
3a8e1175bSopenharmony_ci */
4a8e1175bSopenharmony_ci/*
5a8e1175bSopenharmony_ci *  Copyright The Mbed TLS Contributors
6a8e1175bSopenharmony_ci *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7a8e1175bSopenharmony_ci */
8a8e1175bSopenharmony_ci
9a8e1175bSopenharmony_ci#include <stdlib.h>
10a8e1175bSopenharmony_ci
11a8e1175bSopenharmony_ci#ifndef MBEDTLS_PLATFORM_STD_CALLOC
12a8e1175bSopenharmony_cistatic inline void *custom_calloc(size_t nmemb, size_t size)
13a8e1175bSopenharmony_ci{
14a8e1175bSopenharmony_ci    if (nmemb == 0 || size == 0) {
15a8e1175bSopenharmony_ci        return NULL;
16a8e1175bSopenharmony_ci    }
17a8e1175bSopenharmony_ci    return calloc(nmemb, size);
18a8e1175bSopenharmony_ci}
19a8e1175bSopenharmony_ci
20a8e1175bSopenharmony_ci#define MBEDTLS_PLATFORM_MEMORY
21a8e1175bSopenharmony_ci#define MBEDTLS_PLATFORM_STD_CALLOC custom_calloc
22a8e1175bSopenharmony_ci#endif
23