home *** CD-ROM | disk | FTP | other *** search
- /* Copyright 1988 Regents of the University of California */
-
- #ifndef lint
- static char SCCSid[] = "@(#)ealloc.c 1.2 2/2/89 LBL";
- #endif
-
- /*
- * ealloc.c - memory routines which call exit on error.
- */
-
-
- #include <stdio.h>
-
-
- char *malloc(), *realloc(), *Emalloc(), *Ecalloc(), *Erealloc();
-
-
- char *
- Emalloc(n) /* return pointer to n uninitialized bytes */
- unsigned n;
- {
- register char *cp;
-
- if (n == 0)
- return(NULL);
-
- if ((cp = malloc(n)) != NULL)
- return(cp);
-
- fprintf(stderr, "Out of memory in emalloc\n");
- exit(1);
- }
-
-
- char *
- Ecalloc(ne, es) /* return pointer to initialized memory */
- register unsigned ne;
- unsigned es;
- {
- register char *cp;
-
- ne *= es;
- if (ne == 0)
- return(NULL);
-
- if ((cp = malloc(ne)) == NULL) {
- fprintf(stderr, "Out of memory in ecalloc\n");
- exit(1);
- }
- cp += ne;
- while (ne--) *--cp = 0;
- return(cp);
- }
-
-
- char *
- Erealloc(cp, n) /* reallocate cp to size n */
- register char *cp;
- unsigned n;
- {
- if (n == 0) {
- if (cp != NULL)
- free(cp);
- return(NULL);
- }
-
- if (cp == NULL)
- cp = malloc(n);
- else
- cp = realloc(cp, n);
-
- if (cp != NULL)
- return(cp);
-
- fprintf(stderr, "Out of memory in erealloc\n");
- exit(1);
- }
-
-
- Efree(cp) /* free memory allocated by above */
- char *cp;
- {
- free(cp);
- }
-