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