ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/ealloc.c
Revision: 2.3
Committed: Tue Feb 25 02:47:21 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.2: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

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