date and time created 91/03/03 00:38:20 by donn
[unix-history] / usr / src / contrib / sc / xmalloc.c
CommitLineData
438c3e39
KB
1/*
2 * A safer saner malloc, for careless programmers
3 * $Revision: 6.8 $
4 */
5
6#include <stdio.h>
7#include <curses.h>
8#include "sc.h"
9
10extern char *malloc();
11
12#ifdef SYSV3
13extern void free();
14extern void exit();
15#endif
16
17char *
18xmalloc(n)
19unsigned n;
20{
21register char *ptr;
22
23if ((ptr = malloc(n + sizeof(double))) == NULL)
24 fatal("xmalloc: no memory");
25*((int *) ptr) = 12345; /* magic number */
26return(ptr + sizeof(double));
27}
28
29xfree(p)
30char *p;
31{
32if (p == NULL)
33 fatal("xfree: NULL");
34p -= sizeof(double);
35if (*((int *) p) != 12345)
36 fatal("xfree: storage not malloc'ed");
37free(p);
38}
39
40fatal(str)
41char *str;
42{
43 deraw();
44 (void) fprintf(stderr,"%s\n", str);
45 exit(1);
46}