ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/ealloc.c
(Generate patch)

Comparing ray/src/common/ealloc.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:34:30 1989 UTC vs.
Revision 2.10 by greg, Sat Jan 15 02:00:21 2022 UTC

# Line 1 | Line 1
1 /*
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
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 + #include "rterror.h"
15 + #include "rtmisc.h"
16  
17 < char  *malloc(), *realloc(), *emalloc(), *ecalloc(), *erealloc();
18 <
15 <
16 < char *
17 < emalloc(n)                      /* return pointer to n uninitialized bytes */
18 < unsigned  n;
17 > void *                  /* return pointer to n uninitialized bytes */
18 > emalloc(size_t  n)
19   {
20 <        register char  *cp;
20 >        void  *cp;
21          
22          if (n == 0)
23                  return(NULL);
# Line 27 | Line 27 | unsigned  n;
27  
28          eputs("Out of memory in emalloc\n");
29          quit(1);
30 +        return NULL; /* pro forma return */
31   }
32  
33  
34 < char *
35 < ecalloc(ne, es)                 /* return pointer to initialized memory */
35 < register unsigned  ne;
36 < unsigned  es;
34 > void *                  /* return pointer to initialized memory */
35 > ecalloc(size_t ne, size_t es)
36   {
37 <        register char  *cp;
37 >        void  *cp;
38          
39 <        ne *= es;
41 <        if (ne == 0)
39 >        if (!ne | !es)
40                  return(NULL);
41  
42 <        if ((cp = malloc(ne)) == NULL) {
43 <                eputs("Out of memory in ecalloc\n");
44 <                quit(1);
45 <        }
46 <        cp += ne;
47 <        while (ne--)
50 <                *--cp = 0;
51 <        return(cp);
42 >        if ((cp = ecalloc(ne, es)) != NULL)
43 >                return(cp);
44 >
45 >        eputs("Out of memory in ecalloc\n");
46 >        quit(1);
47 >        return(NULL); /* pro forma return */
48   }
49  
50  
51 < char *
52 < erealloc(cp, n)                 /* reallocate cp to size n */
57 < register char  *cp;
58 < unsigned  n;
51 > void *                  /* reallocate cp to size n */
52 > erealloc(void  *cp, size_t  n)
53   {
54          if (n == 0) {
55                  if (cp != NULL)
# Line 73 | Line 67 | unsigned  n;
67  
68          eputs("Out of memory in erealloc\n");
69          quit(1);
70 +        return NULL; /* pro forma return */
71   }
72  
73  
74 < efree(cp)                       /* free memory allocated by above */
75 < char  *cp;
74 > void                    /* free memory allocated by above */
75 > efree(void *cp)
76   {
77 <        free(cp);
77 >        if (cp)
78 >                free(cp);
79   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines