Initial import from FreeBSD RELENG_4:
[dragonfly.git] / games / hack / alloc.c
1 /* alloc.c - version 1.0.2 */
2 /* $FreeBSD: src/games/hack/alloc.c,v 1.4 1999/11/16 02:57:01 billf Exp $ */
3
4 #include <stdlib.h>
5
6 #ifdef LINT
7
8 /*
9    a ridiculous definition, suppressing
10         "possible pointer alignment problem" for (long *) malloc()
11         "enlarg defined but never used"
12         "ftell defined (in <stdio.h>) but never used"
13    from lint
14 */
15 #include <stdio.h>
16 long *
17 alloc(n) unsigned n; {
18 long dummy = ftell(stderr);
19         if(n) dummy = 0;        /* make sure arg is used */
20         return(&dummy);
21 }
22
23 #else
24
25 long *
26 alloc(lth)
27 unsigned lth;
28 {
29         char *ptr;
30
31         if(!(ptr = malloc(lth)))
32                 panic("Cannot get %d bytes", lth);
33         return((long *) ptr);
34 }
35
36 long *
37 enlarge(ptr,lth)
38 char *ptr;
39 unsigned lth;
40 {
41         char *nptr;
42
43         if(!(nptr = realloc(ptr,lth)))
44                 panic("Cannot reallocate %d bytes", lth);
45         return((long *) nptr);
46 }
47
48 #endif LINT