Source:NetHack 2.2a/alloc.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to alloc.c from the source code of NetHack 2.2a.

Warning! This is the source code from an old release. For newer releases, see Source code

Screenshots and source code from Hack are used under the CWI license.

1.    /*	SCCS Id: @(#)alloc.c	1.4	87/08/08
2.    /* alloc.c - version 1.0.2 */
3.    #ifdef LINT
4.    
5.    /*
6.       a ridiculous definition, suppressing
7.    	"possible pointer alignment problem" for (long *) malloc()
8.    	"enlarg defined but never used"
9.    	"ftell defined (in <stdio.h>) but never used"
10.      from lint
11.   */
12.   #include <stdio.h>
13.   long *
14.   alloc(n) unsigned n; {
15.   long dummy = ftell(stderr);
16.   	if(n) dummy = 0;	/* make sure arg is used */
17.   	return(&dummy);
18.   }
19.   
20.   #else
21.   
22.   extern char *malloc();
23.   extern char *realloc();
24.   
25.   long *
26.   alloc(lth)
27.   register unsigned lth;
28.   {
29.   	register char *ptr;
30.   
31.   	if(!(ptr = malloc(lth)))
32.   		panic("Cannot get %d bytes", lth);
33.   	return((long *) ptr);
34.   }
35.   
36.   #ifndef DGK
37.   long *
38.   enlarge(ptr,lth)
39.   register char *ptr;
40.   register unsigned lth;
41.   {
42.   	register char *nptr;
43.   
44.   	if(!(nptr = realloc(ptr,lth)))
45.   		panic("Cannot reallocate %d bytes", lth);
46.   	return((long *) nptr);
47.   }
48.   #endif
49.   
50.   #endif /* LINT /**/