Mercurial > ~darius > hgwebdir.cgi > mikmod
comparison mmio/mmalloc.c @ 10:55420dceb8e0
Initial entry of mikmod into the CVS tree.
author | darius |
---|---|
date | Fri, 23 Jan 1998 16:05:11 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:990c9dadb348 | 10:55420dceb8e0 |
---|---|
1 /* | |
2 --> The MMIO Portable Memory Management functions | |
3 -> Divine Entertainment GameDev Libraries | |
4 | |
5 Copyright © 1997 by Jake Stine and Divine Entertainment | |
6 | |
7 */ | |
8 | |
9 #include "mmio.h" | |
10 | |
11 | |
12 // Same as malloc, but sets error variable _mm_error when it failed | |
13 void *_mm_malloc(size_t size) | |
14 { | |
15 void *d; | |
16 | |
17 if((d=malloc(size))==NULL) | |
18 { _mm_errno = MMERR_OUT_OF_MEMORY; | |
19 if(_mm_errorhandler!=NULL) _mm_errorhandler(); | |
20 } | |
21 | |
22 return d; | |
23 } | |
24 | |
25 | |
26 // Same as calloc, but sets error variable _mm_error when it failed | |
27 void *_mm_calloc(size_t nitems, size_t size) | |
28 { | |
29 void *d; | |
30 | |
31 if((d=calloc(nitems,size))==NULL) | |
32 { _mm_errno = MMERR_OUT_OF_MEMORY; | |
33 if(_mm_errorhandler!=NULL) _mm_errorhandler(); | |
34 } | |
35 | |
36 return d; | |
37 } | |
38 | |
39 | |
40 #ifndef __WATCOMC__ | |
41 #ifndef __GNUC__ | |
42 // Same as Watcom's strdup function - allocates memory for a string | |
43 // and makes a copy of it. Ruturns NULL if failed. | |
44 CHAR *strdup(CHAR *src) | |
45 { | |
46 CHAR *buf; | |
47 | |
48 if((buf = (CHAR *)_mm_malloc(strlen(src)+1)) == NULL) | |
49 { _mm_errno = MMERR_OUT_OF_MEMORY; | |
50 if(_mm_errorhandler!=NULL) _mm_errorhandler(); | |
51 return NULL; | |
52 } | |
53 | |
54 strcpy(buf,src); | |
55 return buf; | |
56 } | |
57 #endif | |
58 #endif | |
59 |