Difference between revisions of "Source:Hack 1.0/alloc.c"

From NetHackWiki
Jump to navigation Jump to search
m (Automated source code upload test)
 
m (Hack 1.0/alloc.c moved to Source:Hack 1.0/alloc.c: Robot: moved page)
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
'''Warning!''' This is the source code from an old release. For the latest release, see [[Source code]]
 
'''Warning!''' This is the source code from an old release. For the latest release, see [[Source code]]
  
 +
{{CWI}}
 
  <span id="line1">1.    #ifdef LINT</span>
 
  <span id="line1">1.    #ifdef LINT</span>
{{CWI}}
 
 
  <span id="line2">2.    </span>
 
  <span id="line2">2.    </span>
 
  <span id="line3">3.    /*</span>
 
  <span id="line3">3.    /*</span>

Latest revision as of 22:02, 3 March 2008

Below is the full text to alloc.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/alloc.c#line123]], for example.

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

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

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