Fiddling with x86_64 and i486 builds
[tpg/acess2.git] / Usermode / Libraries / libc.so_src / heap.c
index 499d24c..d049070 100644 (file)
@@ -4,6 +4,7 @@ heap.c - Heap Manager
 */\r
 #include <acess/sys.h>\r
 #include <stdlib.h>\r
+#include <string.h>\r
 #include "lib.h"\r
 \r
 // === Constants ===\r
@@ -14,7 +15,7 @@ heap.c - Heap Manager
 \r
 typedef unsigned int Uint;\r
 \r
-//Typedefs\r
+// === TYPES ===\r
 typedef struct {\r
        Uint    magic;\r
        Uint    size;\r
@@ -24,12 +25,13 @@ typedef struct {
        Uint    magic;\r
 }      heap_foot;\r
 \r
-//Globals\r
-void   *_heap_start = NULL;\r
-void   *_heap_end = NULL;\r
+// === LOCAL VARIABLES ===\r
+static void    *_heap_start = NULL;\r
+static void    *_heap_end = NULL;\r
 \r
-//Prototypes\r
-EXPORT void    *malloc(Uint bytes);\r
+// === PROTOTYPES ===\r
+EXPORT void    *malloc(size_t bytes);\r
+EXPORT void    *calloc(size_t bytes, size_t count);\r
 EXPORT void    free(void *mem);\r
 EXPORT void    *realloc(void *mem, Uint bytes);\r
 EXPORT void    *sbrk(int increment);\r
@@ -133,6 +135,20 @@ EXPORT void *malloc(size_t bytes)
        return (void*)(bestMatchAddr+sizeof(heap_head));\r
 }\r
 \r
+/**\r
+ * \fn EXPORT void *calloc(size_t bytes, size_t count)\r
+ * \brief Allocate and zero a block of memory\r
+ * \param __nmemb      Number of memeber elements\r
+ * \param __size       Size of one element\r
+ */\r
+EXPORT void *calloc(size_t __nmemb, size_t __size)\r
+{\r
+       void    *ret = malloc(__size*__nmemb);\r
+       if(!ret)        return NULL;\r
+       memset(ret, 0, __size*__nmemb);\r
+       return ret;\r
+}\r
+\r
 /**\r
  \fn EXPORT void free(void *mem)\r
  \brief Free previously allocated memory\r

UCC git Repository :: git.ucc.asn.au