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