ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/ealloc.c
Revision: 2.8
Committed: Fri Nov 14 17:22:06 2003 UTC (20 years, 5 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.7: +3 -1 lines
Log Message:
Reduced compile warnings, and other compatibility fixes.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: ealloc.c,v 2.7 2003/10/27 10:19:31 schorsch Exp $";
3 #endif
4 /*
5 * ealloc.c - memory routines which call quit on error.
6 */
7
8 #include "copyright.h"
9
10
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 #include "rterror.h"
15
16 extern char * /* return pointer to n uninitialized bytes */
17 emalloc(unsigned int n)
18 {
19 register char *cp;
20
21 if (n == 0)
22 return(NULL);
23
24 if ((cp = (char *)malloc(n)) != NULL)
25 return(cp);
26
27 eputs("Out of memory in emalloc\n");
28 quit(1);
29 return NULL; /* pro forma return */
30 }
31
32
33 extern char * /* return pointer to initialized memory */
34 ecalloc(register unsigned int ne, unsigned int es)
35 {
36 register char *cp;
37
38 ne *= es;
39 if (ne == 0)
40 return(NULL);
41
42 if ((cp = (char *)malloc(ne)) == NULL) {
43 eputs("Out of memory in ecalloc\n");
44 quit(1);
45 }
46 cp += ne;
47 while (ne--)
48 *--cp = 0;
49 return(cp);
50 }
51
52
53 extern char * /* reallocate cp to size n */
54 erealloc(register char *cp, unsigned int n)
55 {
56 if (n == 0) {
57 if (cp != NULL)
58 free((void *)cp);
59 return(NULL);
60 }
61
62 if (cp == NULL)
63 cp = (char *)malloc(n);
64 else
65 cp = (char *)realloc((void *)cp, n);
66
67 if (cp != NULL)
68 return(cp);
69
70 eputs("Out of memory in erealloc\n");
71 quit(1);
72 return NULL; /* pro forma return */
73 }
74
75
76 extern void /* free memory allocated by above */
77 efree(char *cp)
78 {
79 free((void *)cp);
80 }