File:  [Research Unix] / researchv10no / cmd / spitbol / wrtaout.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

/*
	wrtaout( headerp,memsize ) writes an executable a.out file containing
	the currently executing spitbol program. headerp is a pointer to
	the a.out header. memsize is the actual memory size of the executing
	program.
*/

int	wrtaout( headerp,memsize )

char	*headerp;
int	memsize;

{
	register int	excess, fd;
	long	lseek();


	unlink( "a.out" );

	if ( (fd = creat( "a.out",0777 )) < 0 )
		return	-1;

	/*
	 *	write a.out header
	 */

	if ( write( fd,headerp,32 ) != 32 )
		return	-2;

	/*
	 *	lseek out to 1024 byte boundary (full page).
	 */

	if ( lseek( fd,1024L,0 ) != 1024 )
		return -3;

	/*
	 *	write all of memory
	 */

	if ( write( fd,0,memsize ) != memsize )
		return	-4;

	/*
	 *	if memsize not multiple of 1024, force file size up to
	 *	this multiple.
	 */

	if ( (excess = memsize % 1024) != 0 ) {
		excess	= 1024 - excess;
		if ( lseek( fd,(long) excess - 1,1 ) < 0 ) 
			return	-5;
		if ( write( fd,"",1 ) != 1 )
			return	-6;
	}

	close( fd );

	return	0;

}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.