xref: /netbsd/games/hack/alloc.c (revision bf9ec67e)
1 /*	$NetBSD: alloc.c,v 1.4 1997/10/19 16:56:47 christos Exp $	*/
2 #include <sys/cdefs.h>
3 #ifndef lint
4 __RCSID("$NetBSD: alloc.c,v 1.4 1997/10/19 16:56:47 christos Exp $");
5 #endif				/* not lint */
6 
7 #include <stdlib.h>
8 #include "hack.h"
9 #include "extern.h"
10 
11 #ifdef LINT
12 
13 /*
14    a ridiculous definition, suppressing
15 	"possible pointer alignment problem" for (long *) malloc()
16 	"enlarg defined but never used"
17 	"ftell defined (in <stdio.h>) but never used"
18    from lint
19 */
20 long *
21 alloc(n)
22 	unsigned        n;
23 {
24 	long            dummy = ftell(stderr);
25 	if (n)
26 		dummy = 0;	/* make sure arg is used */
27 	return (&dummy);
28 }
29 
30 #else
31 
32 long *
33 alloc(lth)
34 	unsigned lth;
35 {
36 	char  *ptr;
37 
38 	if (!(ptr = malloc(lth)))
39 		panic("Cannot get %d bytes", lth);
40 	return ((long *) ptr);
41 }
42 
43 long *
44 enlarge(ptr, lth)
45 	char  *ptr;
46 	unsigned lth;
47 {
48 	char  *nptr;
49 
50 	if (!(nptr = realloc(ptr, lth)))
51 		panic("Cannot reallocate %d bytes", lth);
52 	return ((long *) nptr);
53 }
54 
55 #endif	/* LINT */
56