--- ray/src/common/ealloc.c 1991/11/12 16:54:23 2.1 +++ ray/src/common/ealloc.c 2022/01/15 02:00:21 2.10 @@ -1,25 +1,23 @@ -/* Copyright 1988 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ealloc.c,v 2.10 2022/01/15 02:00:21 greg Exp $"; #endif - /* * ealloc.c - memory routines which call quit on error. */ +#include "copyright.h" + #include +#include +#include "rterror.h" +#include "rtmisc.h" -char *malloc(), *realloc(), *emalloc(), *ecalloc(), *erealloc(); - - -char * -emalloc(n) /* return pointer to n uninitialized bytes */ -unsigned n; +void * /* return pointer to n uninitialized bytes */ +emalloc(size_t n) { - register char *cp; + void *cp; if (n == 0) return(NULL); @@ -29,35 +27,29 @@ unsigned n; eputs("Out of memory in emalloc\n"); quit(1); + return NULL; /* pro forma return */ } -char * -ecalloc(ne, es) /* return pointer to initialized memory */ -register unsigned ne; -unsigned es; +void * /* return pointer to initialized memory */ +ecalloc(size_t ne, size_t es) { - register char *cp; + void *cp; - ne *= es; - if (ne == 0) + if (!ne | !es) return(NULL); - if ((cp = malloc(ne)) == NULL) { - eputs("Out of memory in ecalloc\n"); - quit(1); - } - cp += ne; - while (ne--) - *--cp = 0; - return(cp); + if ((cp = ecalloc(ne, es)) != NULL) + return(cp); + + eputs("Out of memory in ecalloc\n"); + quit(1); + return(NULL); /* pro forma return */ } -char * -erealloc(cp, n) /* reallocate cp to size n */ -register char *cp; -unsigned n; +void * /* reallocate cp to size n */ +erealloc(void *cp, size_t n) { if (n == 0) { if (cp != NULL) @@ -75,11 +67,13 @@ unsigned n; eputs("Out of memory in erealloc\n"); quit(1); + return NULL; /* pro forma return */ } -efree(cp) /* free memory allocated by above */ -char *cp; +void /* free memory allocated by above */ +efree(void *cp) { - free(cp); + if (cp) + free(cp); }