xref: /csrg-svn/sys/stand/copy.c (revision 63370)
163272Smckusick /*-
2*63370Sbostic  * Copyright (c) 1993
3*63370Sbostic  *	The Regents of the University of California.  All rights reserved.
463272Smckusick  *
563272Smckusick  * %sccs.include.redist.c%
663272Smckusick  */
763272Smckusick 
863272Smckusick #ifndef lint
9*63370Sbostic static char copyright[] =
10*63370Sbostic "@(#) Copyright (c) 1993\n\
11*63370Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1263272Smckusick #endif /* not lint */
1363272Smckusick 
1463272Smckusick #ifndef lint
15*63370Sbostic static char sccsid[] = "@(#)copy.c	8.1 (Berkeley) 06/11/93";
1663272Smckusick #endif /* not lint */
1763272Smckusick 
1863272Smckusick #define	BSIZE	10240
1963272Smckusick 
2063272Smckusick /*
2163272Smckusick  * Copy from from to to.  Intended for use in system installation.
2263272Smckusick  */
main()2363272Smckusick main()
2463272Smckusick {
2563272Smckusick 	extern int errno;
2663272Smckusick 	register int from, to, record, rcc, wcc, bsize = BSIZE;
2763272Smckusick 	char buf[BSIZE];
2863272Smckusick 
2963272Smckusick 	from = getfile("From", 0);
3063272Smckusick 	to = getfile("To", 1);
3163272Smckusick 	for (record = 0;; ++record) {
3263272Smckusick 		if (!(rcc = read(from, buf, bsize)))
3363272Smckusick 			break;
3463272Smckusick 		if (rcc < 0) {
3563272Smckusick 			printf("Record %d: read error, errno=%d\n",
3663272Smckusick 			    record, errno);
3763272Smckusick 			break;
3863272Smckusick 		}
3963272Smckusick 		if (rcc != bsize) {
4063272Smckusick 			if (record == 0) {
4163272Smckusick 				bsize = rcc;
4263272Smckusick 				printf("Block size set from input; %d bytes\n",
4363272Smckusick 				    bsize);
4463272Smckusick 			} else
4563272Smckusick 				printf("Record %d: read short; expected %d, got %d\n",
4663272Smckusick 				    record, bsize, rcc);
4763272Smckusick 		}
4863272Smckusick #ifdef vax
4963272Smckusick 		/* For bug in ht driver. */
5063272Smckusick 		if (rcc > bsize)
5163272Smckusick 			rcc = bsize;
5263272Smckusick #endif
5363272Smckusick 		if ((wcc = write(to, buf, rcc)) < 0) {
5463272Smckusick 			printf("Record %d: write error: errno=%d\n",
5563272Smckusick 			    record, errno);
5663272Smckusick 			break;
5763272Smckusick 		}
5863272Smckusick 		if (wcc < rcc) {
5963272Smckusick 			printf("Record %d: write short; expected %d, got %d\n",
6063272Smckusick 			    record, rcc, wcc);
6163272Smckusick 			break;
6263272Smckusick 		}
6363272Smckusick 	}
6463272Smckusick 	printf("copy completed: %d records copied\n", record);
6563272Smckusick }
66