X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc.so_src%2Fheap.c;h=d04907077d14f17685d2bfa89fdc6da6554e5c56;hb=25f7e9ab0f31ca486c0c981a406d381e160637a4;hp=499d24c928415fd1a621d522d9f94acc10a2225b;hpb=47e9dfd89189fc6b150bd6b20229cb047c7e0858;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc.so_src/heap.c b/Usermode/Libraries/libc.so_src/heap.c index 499d24c9..d0490707 100644 --- a/Usermode/Libraries/libc.so_src/heap.c +++ b/Usermode/Libraries/libc.so_src/heap.c @@ -4,6 +4,7 @@ heap.c - Heap Manager */ #include #include +#include #include "lib.h" // === Constants === @@ -14,7 +15,7 @@ heap.c - Heap Manager typedef unsigned int Uint; -//Typedefs +// === TYPES === typedef struct { Uint magic; Uint size; @@ -24,12 +25,13 @@ typedef struct { Uint magic; } heap_foot; -//Globals -void *_heap_start = NULL; -void *_heap_end = NULL; +// === LOCAL VARIABLES === +static void *_heap_start = NULL; +static void *_heap_end = NULL; -//Prototypes -EXPORT void *malloc(Uint bytes); +// === PROTOTYPES === +EXPORT void *malloc(size_t bytes); +EXPORT void *calloc(size_t bytes, size_t count); EXPORT void free(void *mem); EXPORT void *realloc(void *mem, Uint bytes); EXPORT void *sbrk(int increment); @@ -133,6 +135,20 @@ EXPORT void *malloc(size_t bytes) return (void*)(bestMatchAddr+sizeof(heap_head)); } +/** + * \fn EXPORT void *calloc(size_t bytes, size_t count) + * \brief Allocate and zero a block of memory + * \param __nmemb Number of memeber elements + * \param __size Size of one element + */ +EXPORT void *calloc(size_t __nmemb, size_t __size) +{ + void *ret = malloc(__size*__nmemb); + if(!ret) return NULL; + memset(ret, 0, __size*__nmemb); + return ret; +} + /** \fn EXPORT void free(void *mem) \brief Free previously allocated memory