+
+
+#else /* SYSMALLOC */
+
+/**
+ ** ``Protected versions'' of malloc, realloc, calloc, and free
+ **
+ ** On many systems:
+ **
+ ** 1. malloc(0) is bad
+ ** 2. free(0) is bad
+ ** 3. realloc(0, n) is bad
+ ** 4. realloc(n, 0) is bad
+ **
+ ** Also we call our error routine if we run out of memory.
+ **/
+char *
+Malloc(n)
+ size_t n;
+{
+ ptr_t ptr;
+
+ n = n ? n : 1;
+
+ if ((ptr = malloc(n)) == (ptr_t) 0) {
+ child++;
+ stderror(ERR_NOMEM);
+ }
+ return ((char *) ptr);
+}
+
+char *
+Realloc(p, n)
+ ptr_t p;
+ size_t n;
+{
+ ptr_t ptr;
+
+ n = n ? n : 1;
+ if ((ptr = (p ? realloc(p, n) : malloc(n))) == (ptr_t) 0) {
+ child++;
+ stderror(ERR_NOMEM);
+ }
+ return ((char *) ptr);
+}
+
+char *
+Calloc(s, n)
+ size_t s, n;
+{
+ char *sptr;
+ ptr_t ptr;
+
+ n *= s;
+ n = n ? n : 1;
+ if ((ptr = malloc(n)) == (ptr_t) 0) {
+ child++;
+ stderror(ERR_NOMEM);
+ }
+
+ sptr = (char *) ptr;
+ if (n != 0)
+ do
+ *sptr++ = 0;
+ while (--n);
+
+ return ((char *) ptr);
+}
+
+void
+Free(p)
+ ptr_t p;
+{
+ if (p)
+ free(p);
+}
+
+#endif /* SYSMALLOC */
+
+/*
+ * mstats - print out statistics about malloc
+ *
+ * Prints two lines of numbers, one showing the length of the free list
+ * for each size category, the second showing the number of mallocs -
+ * frees for each size category.
+ */
+void
+/*ARGSUSED*/
+showall(v, t)
+ Char **v;
+ struct command *t;
+{
+#ifndef SYSMALLOC
+ register int i, j;
+ register union overhead *p;
+ int totfree = 0, totused = 0;
+
+ (void) fprintf(cshout, "csh current memory allocation:\nfree:\t");
+ for (i = 0; i < NBUCKETS; i++) {
+ for (j = 0, p = nextf[i]; p; p = p->ov_next, j++);
+ (void) fprintf(cshout, " %4d", j);
+ totfree += j * (1 << (i + 3));
+ }
+ (void) fprintf(cshout, "\nused:\t");
+ for (i = 0; i < NBUCKETS; i++) {
+ (void) fprintf(cshout, "%4d", nmalloc[i]);
+ totused += nmalloc[i] * (1 << (i + 3));
+ }
+ (void) fprintf(cshout, "\n\tTotal in use: %d, total free: %d\n",
+ totused, totfree);
+ (void) fprintf(cshout,
+ "\tAllocated memory from 0x%lx to 0x%lx. Real top at 0x%lx\n",
+ membot, memtop, (char *) sbrk(0));
+#else
+ (void) fprintf(cshout, "Allocated memory from 0x%lx to 0x%lx (%ld).\n",
+ membot, memtop = (char *) sbrk(0), memtop - membot);
+#endif /* SYSMALLOC */
+}