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 |
|
|
13 |
– |
char *malloc(), *realloc(), *emalloc(), *ecalloc(), *erealloc(); |
14 |
– |
|
15 |
– |
|
15 |
|
char * |
16 |
|
emalloc(n) /* return pointer to n uninitialized bytes */ |
17 |
< |
unsigned n; |
17 |
> |
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"); |
31 |
|
|
32 |
|
char * |
33 |
|
ecalloc(ne, es) /* return pointer to initialized memory */ |
34 |
< |
register unsigned ne; |
35 |
< |
unsigned es; |
34 |
> |
register unsigned int ne; |
35 |
> |
unsigned int es; |
36 |
|
{ |
37 |
|
register char *cp; |
38 |
|
|
40 |
|
if (ne == 0) |
41 |
|
return(NULL); |
42 |
|
|
43 |
< |
if ((cp = malloc(ne)) == NULL) { |
43 |
> |
if ((cp = (char *)malloc(ne)) == NULL) { |
44 |
|
eputs("Out of memory in ecalloc\n"); |
45 |
|
quit(1); |
46 |
|
} |
54 |
|
char * |
55 |
|
erealloc(cp, n) /* reallocate cp to size n */ |
56 |
|
register char *cp; |
57 |
< |
unsigned n; |
57 |
> |
unsigned int n; |
58 |
|
{ |
59 |
|
if (n == 0) { |
60 |
|
if (cp != NULL) |
61 |
< |
free(cp); |
61 |
> |
free((void *)cp); |
62 |
|
return(NULL); |
63 |
|
} |
64 |
|
|
65 |
|
if (cp == NULL) |
66 |
< |
cp = malloc(n); |
66 |
> |
cp = (char *)malloc(n); |
67 |
|
else |
68 |
< |
cp = realloc(cp, n); |
68 |
> |
cp = (char *)realloc((void *)cp, n); |
69 |
|
|
70 |
|
if (cp != NULL) |
71 |
|
return(cp); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
+ |
void |
79 |
|
efree(cp) /* free memory allocated by above */ |
80 |
|
char *cp; |
81 |
|
{ |
82 |
< |
free(cp); |
82 |
> |
free((void *)cp); |
83 |
|
} |