From 4841d83ff877abe2a253068bf2c7ad5913ba28c9 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 24 Dec 2011 04:05:38 +0100 Subject: [PATCH] Added calloc(3). --- libmaxsi/c/hsrc/stdlib.h | 2 +- libmaxsi/heap.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libmaxsi/c/hsrc/stdlib.h b/libmaxsi/c/hsrc/stdlib.h index e700b5a9..a65bcac9 100644 --- a/libmaxsi/c/hsrc/stdlib.h +++ b/libmaxsi/c/hsrc/stdlib.h @@ -46,6 +46,7 @@ typedef int div_t, ldiv_t, lldiv_t; /* TODO: WEXITSTATUS, WIFEXITED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED is missing here */ int atoi(const char*); +void* calloc(size_t, size_t); void exit(int); void _Exit(int status); void free(void*); @@ -67,7 +68,6 @@ int atoi(const char*); long atol(const char*); long long atoll(const char*); void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*)); -void* calloc(size_t, size_t); div_t div(int, int); double drand48(void); double erand48(unsigned short [3]); diff --git a/libmaxsi/heap.cpp b/libmaxsi/heap.cpp index 92498966..2156520e 100644 --- a/libmaxsi/heap.cpp +++ b/libmaxsi/heap.cpp @@ -642,6 +642,15 @@ namespace Maxsi ASSERT(ValidateHeap()); #endif } + + extern "C" void* calloc(size_t nmemb, size_t size) + { + size_t total = nmemb * size; + void* result = Allocate(total); + if ( !result ) { return NULL; } + Memory::Set(result, 0, total); + return result; + } } }