[net.micro.atari] ST Source: onedsk.c

mdf@trwrba.UUCP (Mark D. Falleroni) (11/04/85)

The is an ST program that executes from the Hippo OS shell. It allows
files (up to 28000 bytes) to be copied with only one disk swap.

- - - - - - - - cut here - - - - - - - - cut here - - - - - - - -
#include <stdio.h>
#define MEMBUF 28000
#define READ 0
#define WRITE 1
#define BUFSIZE 1024


main(argc,argv)
int argc;
char *argv[];

{
 int handle,n,bytes_read,cnt,i,c;
 char bigbuf[MEMBUF];

	if (argc != 3)
	 error("ONEDSK usage: onedsk source file destination file",NULL);

	printf("\nOpening %s\n",argv[1]);

	if ((handle = open(argv[1],READ)) < 0)
	 error("ONEDSK: error opening %s",argv[1]);

	n=0;
	bytes_read=0;

	while ((n = read(handle,BUFSIZE,bigbuf+bytes_read)) > 0)
	{
	 bytes_read += n;
	 printf("Bytes read = %d\n",bytes_read);
	}

	close (handle);

	printf("\n\n");
	printf("Insert destination disk in Drive A:\n");
	printf("Type any key when ready\n");
	necin();	  /* get char with no screen echo */

	printf("\nCreating %s on the destination disk\n",argv[2]);

	if ((handle = create(argv[2],0777)) < 0)		/* if can't create it */
	 handle = open(argv[2],WRITE);  		/* try opening it */
	if (handle < 0)
	 error("ONEDSK: cannot create or open %s",argv[2]);

	if ((n = write(handle,bytes_read,bigbuf)) < 0)
	 error("ONEDSK: error writing to %s",argv[2]);
	printf("\nBytes written = %d\n",n);

	close(handle);

	if (n == bytes_read)
	 printf("\nCOPY COMPLETED\n\n");
	else
	 printf("\nBYTE COUNT MISMATCH: BAD COPY!\n\n");

}

error(s1,s2)
char *s1, *s2;

{
 printf(s1,s2);
 printf("\n");
 exit(1);
}