xref: /original-bsd/sys/stand.att/copy.c (revision e811aa08)
1d44b9aafSbostic /*-
2*e811aa08Sbostic  * Copyright (c) 1982, 1986, 1988, 1993
3*e811aa08Sbostic  *	The Regents of the University of California.  All rights reserved.
4a8638090Smckusick  *
5d44b9aafSbostic  * %sccs.include.redist.c%
6d44b9aafSbostic  *
7*e811aa08Sbostic  *	@(#)copy.c	8.1 (Berkeley) 06/11/93
8a8638090Smckusick  */
985fb39b8Ssam 
107520acd5Sbostic #define	BSIZE	10240
117520acd5Sbostic 
1285fb39b8Ssam /*
137520acd5Sbostic  * Copy from from to to.  Intended for use in system installation.
1485fb39b8Ssam  */
main()1585fb39b8Ssam main()
1685fb39b8Ssam {
173af48ffbSsam 	extern int errno;
183aaddff2Skarels 	register int from, to, record, rcc, wcc, bsize = BSIZE;
197520acd5Sbostic 	char buf[BSIZE];
2085fb39b8Ssam 
21b103beccSbostic 	from = getfile("From", 0);
22b103beccSbostic 	to = getfile("To", 1);
237520acd5Sbostic 	for (record = 0;; ++record) {
243aaddff2Skarels 		if (!(rcc = read(from, buf, bsize)))
2585fb39b8Ssam 			break;
263af48ffbSsam 		if (rcc < 0) {
27089cce68Ssam 			printf("Record %d: read error, errno=%d\n",
28089cce68Ssam 			    record, errno);
293af48ffbSsam 			break;
3085fb39b8Ssam 		}
313aaddff2Skarels 		if (rcc != bsize) {
323aaddff2Skarels 			if (record == 0) {
333aaddff2Skarels 				bsize = rcc;
343aaddff2Skarels 				printf("Block size set from input; %d bytes\n",
353aaddff2Skarels 				    bsize);
363aaddff2Skarels 			} else
373af48ffbSsam 				printf("Record %d: read short; expected %d, got %d\n",
383aaddff2Skarels 				    record, bsize, rcc);
393aaddff2Skarels 		}
407520acd5Sbostic #ifdef vax
417520acd5Sbostic 		/* For bug in ht driver. */
423aaddff2Skarels 		if (rcc > bsize)
433aaddff2Skarels 			rcc = bsize;
447520acd5Sbostic #endif
457520acd5Sbostic 		if ((wcc = write(to, buf, rcc)) < 0) {
46089cce68Ssam 			printf("Record %d: write error: errno=%d\n",
47089cce68Ssam 			    record, errno);
483af48ffbSsam 			break;
493af48ffbSsam 		}
50b9d511d3Ssam 		if (wcc < rcc) {
51089cce68Ssam 			printf("Record %d: write short; expected %d, got %d\n",
52089cce68Ssam 			    record, rcc, wcc);
533af48ffbSsam 			break;
543af48ffbSsam 		}
553af48ffbSsam 	}
567520acd5Sbostic 	printf("copy completed: %d records copied\n", record);
5785fb39b8Ssam }
58