view mmio/mmalloc.c @ 15:ca72d2b59bf4

Kill this stuff.. Rewriting the frontend
author darius
date Thu, 23 Apr 1998 07:22:22 +0000
parents 55420dceb8e0
children
line wrap: on
line source

/*
 --> The MMIO Portable Memory Management functions
  -> Divine Entertainment GameDev Libraries

 Copyright © 1997 by Jake Stine and Divine Entertainment

*/

#include "mmio.h"


// Same as malloc, but sets error variable _mm_error when it failed
void *_mm_malloc(size_t size)
{
    void *d;

    if((d=malloc(size))==NULL)
    {   _mm_errno = MMERR_OUT_OF_MEMORY;
        if(_mm_errorhandler!=NULL) _mm_errorhandler();
    }

    return d;
}


// Same as calloc, but sets error variable _mm_error when it failed
void *_mm_calloc(size_t nitems, size_t size)
{
    void *d;
   
    if((d=calloc(nitems,size))==NULL)
    {   _mm_errno = MMERR_OUT_OF_MEMORY;
        if(_mm_errorhandler!=NULL) _mm_errorhandler();
    }

    return d;
}


#ifndef __WATCOMC__
#ifndef __GNUC__
// Same as Watcom's strdup function - allocates memory for a string
// and makes a copy of it.  Ruturns NULL if failed.
CHAR *strdup(CHAR *src)
{
    CHAR *buf;

    if((buf = (CHAR *)_mm_malloc(strlen(src)+1)) == NULL)
    {   _mm_errno = MMERR_OUT_OF_MEMORY;
        if(_mm_errorhandler!=NULL) _mm_errorhandler();
        return NULL;
    }

    strcpy(buf,src);
    return buf;
}
#endif
#endif