Commit f9479e00 authored by Ulrich Huber's avatar Ulrich Huber Committed by Oliver Horst
Browse files

[add] Calloc implementation

parent 2a8864a7
#ifndef TOKI_MALLOC_H
#define TOKI_MALLOC_H
#include <sys/malloc.h>
void *calloc(size_t nmemb, size_t size);
#endif //TOKI_MALLOC_H
......@@ -2,8 +2,8 @@
// Created by huber on 7/13/20.
//
#ifndef TOKI_MALLOC_H
#define TOKI_MALLOC_H
#ifndef TOKI_SYS_MALLOC_H
#define TOKI_SYS_MALLOC_H
/**
* Initialize malloc with a memory address and pool size
......@@ -22,4 +22,4 @@ void * fl_malloc(size_t size);
#define free fl_free
void fl_free(void * ptr);
#endif //TOKI_MALLOC_H
#endif //TOKI_SYS_MALLOC_H
......@@ -20,12 +20,13 @@ find_package(
add_library(
toki-libc-repl-sys
#
INTERFACE
STATIC
""
)
target_link_libraries(
toki-libc-repl-sys
INTERFACE toki-libc-repl-sys-headers
PUBLIC toki-libc-repl-sys-headers
)
......
#ifndef TOKI_MALLOC_H
#define TOKI_MALLOC_H
#ifndef TOKI_SYS_MALLOC_H
#define TOKI_SYS_MALLOC_H
#include <freertos/FreeRTOS.h>
#include <freertos/portable.h>
......@@ -7,4 +7,4 @@
#define malloc pvPortMalloc
#define free vPortFree
#endif //TOKI_MALLOC_H
#endif //TOKI_SYS_MALLOC_H
......@@ -5,5 +5,6 @@ target_sources(
#
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/atoi.c"
"${CMAKE_CURRENT_LIST_DIR}/calloc.c"
"${CMAKE_CURRENT_LIST_DIR}/rand.c"
)
#include <malloc.h>
#include <string.h>
void *calloc(size_t nmemb, size_t size) {
void *ptr = malloc(nmemb * size);
if (ptr != NULL) {
memset(ptr, 0, nmemb * size);
}
return ptr;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment