annotate mmio/mmalloc.c @ 19:84565bb86869

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