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.2 by greg, Thu Feb 2 13:53:40 1989 UTC vs.
Revision 2.8 by schorsch, Fri Nov 14 17:22:06 2003 UTC

# Line 1 | Line 1
1 /* Copyright 1988 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
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  *malloc(), *realloc(), *emalloc(), *ecalloc(), *erealloc();
17 <
17 <
18 < char *
19 < emalloc(n)                      /* return pointer to n uninitialized bytes */
20 < unsigned  n;
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 = malloc(n)) != NULL)
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 < char *
34 < ecalloc(ne, es)                 /* return pointer to initialized memory */
37 < register unsigned  ne;
38 < unsigned  es;
33 > extern char *                   /* return pointer to initialized memory */
34 > ecalloc(register unsigned int ne, unsigned int es)
35   {
36          register char  *cp;
37          
# Line 43 | Line 39 | unsigned  es;
39          if (ne == 0)
40                  return(NULL);
41  
42 <        if ((cp = malloc(ne)) == NULL) {
42 >        if ((cp = (char *)malloc(ne)) == NULL) {
43                  eputs("Out of memory in ecalloc\n");
44                  quit(1);
45          }
# Line 54 | Line 50 | unsigned  es;
50   }
51  
52  
53 < char *
54 < erealloc(cp, n)                 /* reallocate cp to size n */
59 < register char  *cp;
60 < unsigned  n;
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(cp);
58 >                        free((void *)cp);
59                  return(NULL);
60          }
61  
62          if (cp == NULL)
63 <                cp = malloc(n);
63 >                cp = (char *)malloc(n);
64          else
65 <                cp = realloc(cp, n);
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 < efree(cp)                       /* free memory allocated by above */
77 < char  *cp;
76 > extern void                     /* free memory allocated by above */
77 > efree(char  *cp)
78   {
79 <        free(cp);
79 >        free((void *)cp);
80   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines