break out special local mail processing (e.g., mapping to the
[unix-history] / usr / src / bin / csh / alloc.c
CommitLineData
ecc449eb 1/*-
ed72f0a0
KB
2 * Copyright (c) 1983, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
ecc449eb
KB
4 *
5 * %sccs.include.redist.c%
b79f4fa9
DF
6 */
7
3fb44be6 8#ifndef lint
ed72f0a0 9static char sccsid[] = "@(#)alloc.c 8.1 (Berkeley) %G%";
ecc449eb
KB
10#endif /* not lint */
11
4df6491c
CZ
12#include <sys/types.h>
13#include <unistd.h>
c7c74e2d 14#include <stdlib.h>
4df6491c
CZ
15#if __STDC__
16# include <stdarg.h>
17#else
18# include <varargs.h>
19#endif
20
4d7b2685 21#include "csh.h"
4df6491c 22#include "extern.h"
6e37afca
KB
23
24char *memtop = NULL; /* PWP: top of current memory */
25char *membot = NULL; /* PWP: bottom of allocatable memory */
26
6e37afca 27ptr_t
6e37afca
KB
28Malloc(n)
29 size_t n;
30{
31 ptr_t ptr;
32
c7c74e2d
CZ
33 if (membot == NULL)
34 memtop = membot = sbrk(0);
6e37afca
KB
35 if ((ptr = malloc(n)) == (ptr_t) 0) {
36 child++;
37 stderror(ERR_NOMEM);
38 }
c7c74e2d 39 return (ptr);
6e37afca
KB
40}
41
c7c74e2d 42ptr_t
6e37afca
KB
43Realloc(p, n)
44 ptr_t p;
45 size_t n;
46{
47 ptr_t ptr;
48
c7c74e2d
CZ
49 if (membot == NULL)
50 memtop = membot = sbrk(0);
51 if ((ptr = realloc(p, n)) == (ptr_t) 0) {
6e37afca
KB
52 child++;
53 stderror(ERR_NOMEM);
54 }
c7c74e2d 55 return (ptr);
6e37afca
KB
56}
57
c7c74e2d 58ptr_t
6e37afca
KB
59Calloc(s, n)
60 size_t s, n;
61{
6e37afca
KB
62 ptr_t ptr;
63
c7c74e2d
CZ
64 if (membot == NULL)
65 memtop = membot = sbrk(0);
66 if ((ptr = calloc(s, n)) == (ptr_t) 0) {
6e37afca
KB
67 child++;
68 stderror(ERR_NOMEM);
69 }
70
c7c74e2d 71 return (ptr);
6e37afca
KB
72}
73
74void
75Free(p)
76 ptr_t p;
77{
78 if (p)
79 free(p);
80}
81
3fb44be6
KL
82/*
83 * mstats - print out statistics about malloc
6e37afca 84 *
3fb44be6
KL
85 * Prints two lines of numbers, one showing the length of the free list
86 * for each size category, the second showing the number of mallocs -
87 * frees for each size category.
88 */
6e37afca 89void
454c2aa3
CZ
90/*ARGSUSED*/
91showall(v, t)
92 Char **v;
93 struct command *t;
fc71ebc6 94{
c7c74e2d 95 memtop = (char *) sbrk(0);
454c2aa3 96 (void) fprintf(cshout, "Allocated memory from 0x%lx to 0x%lx (%ld).\n",
37999c01 97 (unsigned long) membot, (unsigned long) memtop, memtop - membot);
fc71ebc6 98}