|
|
1.1 root 1: /*
2: wrtaout( headerp,memsize ) writes an executable a.out file containing
3: the currently executing spitbol program. headerp is a pointer to
4: the a.out header. memsize is the actual memory size of the executing
5: program.
6: */
7:
8: int wrtaout( headerp,memsize )
9:
10: char *headerp;
11: int memsize;
12:
13: {
14: register int excess, fd;
15: long lseek();
16:
17:
18: unlink( "a.out" );
19:
20: if ( (fd = creat( "a.out",0777 )) < 0 )
21: return -1;
22:
23: /*
24: * write a.out header
25: */
26:
27: if ( write( fd,headerp,32 ) != 32 )
28: return -2;
29:
30: /*
31: * lseek out to 1024 byte boundary (full page).
32: */
33:
34: if ( lseek( fd,1024L,0 ) != 1024 )
35: return -3;
36:
37: /*
38: * write all of memory
39: */
40:
41: if ( write( fd,0,memsize ) != memsize )
42: return -4;
43:
44: /*
45: * if memsize not multiple of 1024, force file size up to
46: * this multiple.
47: */
48:
49: if ( (excess = memsize % 1024) != 0 ) {
50: excess = 1024 - excess;
51: if ( lseek( fd,(long) excess - 1,1 ) < 0 )
52: return -5;
53: if ( write( fd,"",1 ) != 1 )
54: return -6;
55: }
56:
57: close( fd );
58:
59: return 0;
60:
61: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.