*/\r
#include <acess/sys.h>\r
#include <stdlib.h>\r
+#include <string.h>\r
#include "lib.h"\r
\r
// === Constants ===\r
\r
typedef unsigned int Uint;\r
\r
-//Typedefs\r
+// === TYPES ===\r
typedef struct {\r
Uint magic;\r
Uint size;\r
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
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
#define UNLOCK(_name) __asm__ __volatile__("lock andl $0, (%0)"::"D"(&_spinlock_##_name))\r
\r
// --- StdLib ---\r
-extern void _exit(int code); //NOTE: Also defined in acess/sys.h\r
+extern void _exit(int code) __attribute__((noreturn)); //NOTE: Also defined in acess/sys.h\r
extern int atoi(const char *ptr);\r
extern void exit(int status) __attribute__((noreturn));\r
extern void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));\r
\r
// --- Heap ---\r
extern void free(void *mem);\r
-extern void *malloc(unsigned int bytes);\r
-extern void *realloc(void *oldPos, unsigned int bytes);\r
+extern void *malloc(size_t bytes);\r
+extern void *calloc(size_t __nmemb, size_t __size);\r
+extern void *realloc(void *__ptr, size_t __size);\r
extern int IsHeap(void *ptr);\r
\r
#ifndef SEEK_CUR\r