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

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