ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/ealloc.c
Revision: 2.6
Committed: Wed Jul 30 10:11:06 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.5: +9 -15 lines
Log Message:
Added prototypes submitted by Randolph Fritz.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: ealloc.c,v 2.5 2003/07/17 09:21:29 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 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 }
30
31
32 char * /* return pointer to initialized memory */
33 ecalloc(register unsigned int ne, unsigned int es)
34 {
35 register char *cp;
36
37 ne *= es;
38 if (ne == 0)
39 return(NULL);
40
41 if ((cp = (char *)malloc(ne)) == NULL) {
42 eputs("Out of memory in ecalloc\n");
43 quit(1);
44 }
45 cp += ne;
46 while (ne--)
47 *--cp = 0;
48 return(cp);
49 }
50
51
52 char * /* reallocate cp to size n */
53 erealloc(register char *cp, unsigned int n)
54 {
55 if (n == 0) {
56 if (cp != NULL)
57 free((void *)cp);
58 return(NULL);
59 }
60
61 if (cp == NULL)
62 cp = (char *)malloc(n);
63 else
64 cp = (char *)realloc((void *)cp, n);
65
66 if (cp != NULL)
67 return(cp);
68
69 eputs("Out of memory in erealloc\n");
70 quit(1);
71 }
72
73
74 void /* free memory allocated by above */
75 efree(char *cp)
76 {
77 free((void *)cp);
78 }