1
0
Fork 0
forked from len0rd/rockbox

renamed to use the common names: malloc/free/realloc/calloc

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@594 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2002-05-16 14:10:28 +00:00
parent 4a615c7885
commit 3eec33f9c6

View file

@ -37,7 +37,7 @@
#include <psos.h> #include <psos.h>
#define SEMAPHORE /* the PSOS routines use semaphore protection */ #define SEMAPHORE /* the PSOS routines use semaphore protection */
#else #else
#include <stdlib.h> /* makes the PSOS complain on the 'size_t' typedef */
#endif #endif
#define BMALLOC /* we use our own big-malloc system */ #define BMALLOC /* we use our own big-malloc system */
@ -290,7 +290,7 @@ void dmalloc_initialize(void)
#ifdef SEMAPHORE #ifdef SEMAPHORE
{ {
char name[7]; char name[7];
sprintf(name, "MEM%d", i); snprintf(name, 7, "MEM%d", i);
SEMAPHORECREATE(name, top[i].semaphore_id); SEMAPHORECREATE(name, top[i].semaphore_id);
/* doesn't matter if it failed, we continue anyway ;-( */ /* doesn't matter if it failed, we continue anyway ;-( */
} }
@ -341,11 +341,11 @@ static void *fragfromblock(struct MemBlock *block)
* *
**************************************************************************/ **************************************************************************/
void *dmalloc(size_t size) void *malloc(size_t size)
{ {
void *mem; void *mem;
DBG(("dmalloc(%d)\n", size)); DBG(("malloc(%d)\n", size));
/* First, we make room for the space needed in every allocation */ /* First, we make room for the space needed in every allocation */
size += sizeof(struct MemInfo); size += sizeof(struct MemInfo);
@ -485,12 +485,12 @@ void *dmalloc(size_t size)
* *
**************************************************************************/ **************************************************************************/
void dfree(void *memp) void free(void *memp)
{ {
struct MemInfo *meminfo = (struct MemInfo *) struct MemInfo *meminfo = (struct MemInfo *)
((char *)memp- sizeof(struct MemInfo)); ((char *)memp- sizeof(struct MemInfo));
DBG(("dfree(%p)\n", memp)); DBG(("free(%p)\n", memp));
if(!((size_t)meminfo->block&BLOCK_BIT)) { if(!((size_t)meminfo->block&BLOCK_BIT)) {
/* this is a FRAGMENT we have to deal with */ /* this is a FRAGMENT we have to deal with */
@ -551,7 +551,7 @@ void dfree(void *memp)
* *
**************************************************************************/ **************************************************************************/
void *drealloc(char *ptr, size_t size) void *realloc(char *ptr, size_t size)
{ {
struct MemInfo *meminfo = (struct MemInfo *) struct MemInfo *meminfo = (struct MemInfo *)
((char *)ptr- sizeof(struct MemInfo)); ((char *)ptr- sizeof(struct MemInfo));
@ -567,10 +567,10 @@ void *drealloc(char *ptr, size_t size)
/* NOTE that this is only valid if BLOCK_BIT isn't set: */ /* NOTE that this is only valid if BLOCK_BIT isn't set: */
struct MemBlock *block; struct MemBlock *block;
DBG(("drealloc(%p, %d)\n", ptr, size)); DBG(("realloc(%p, %d)\n", ptr, size));
if(NULL == ptr) if(NULL == ptr)
return dmalloc( size ); return malloc( size );
block = meminfo->block; block = meminfo->block;
@ -604,10 +604,10 @@ void *drealloc(char *ptr, size_t size)
/* No tricks involved here, just grab a new bite of memory, copy the /* No tricks involved here, just grab a new bite of memory, copy the
* data from the old place and free the old memory again. */ * data from the old place and free the old memory again. */
mem = dmalloc(size); mem = malloc(size);
if(mem) { if(mem) {
memcpy(mem, ptr, MIN(size, prevsize) ); memcpy(mem, ptr, MIN(size, prevsize) );
dfree(ptr); free(ptr);
} }
} }
return mem; return mem;
@ -623,9 +623,9 @@ void *drealloc(char *ptr, size_t size)
/* Allocate an array of NMEMB elements each SIZE bytes long. /* Allocate an array of NMEMB elements each SIZE bytes long.
The entire array is initialized to zeros. */ The entire array is initialized to zeros. */
void * void *
dcalloc (size_t nmemb, size_t size) calloc (size_t nmemb, size_t size)
{ {
void *result = dmalloc (nmemb * size); void *result = malloc (nmemb * size);
if (result != NULL) if (result != NULL)
memset (result, 0, nmemb * size); memset (result, 0, nmemb * size);