xref: /original-bsd/sys/stand.att/copy.c (revision 3aaddff2)
1d44b9aafSbostic /*-
2d44b9aafSbostic  * Copyright (c) 1982, 1986, 1988 The Regents of the University of California.
3d44b9aafSbostic  * All rights reserved.
4a8638090Smckusick  *
5d44b9aafSbostic  * %sccs.include.redist.c%
6d44b9aafSbostic  *
7*3aaddff2Skarels  *	@(#)copy.c	7.7 (Berkeley) 05/21/91
8a8638090Smckusick  */
985fb39b8Ssam 
107520acd5Sbostic #define	BSIZE	10240
117520acd5Sbostic 
1285fb39b8Ssam /*
137520acd5Sbostic  * Copy from from to to.  Intended for use in system installation.
1485fb39b8Ssam  */
1585fb39b8Ssam main()
1685fb39b8Ssam {
173af48ffbSsam 	extern int errno;
18*3aaddff2Skarels 	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) {
24*3aaddff2Skarels 		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 		}
31*3aaddff2Skarels 		if (rcc != bsize) {
32*3aaddff2Skarels 			if (record == 0) {
33*3aaddff2Skarels 				bsize = rcc;
34*3aaddff2Skarels 				printf("Block size set from input; %d bytes\n",
35*3aaddff2Skarels 				    bsize);
36*3aaddff2Skarels 			} else
373af48ffbSsam 				printf("Record %d: read short; expected %d, got %d\n",
38*3aaddff2Skarels 				    record, bsize, rcc);
39*3aaddff2Skarels 		}
407520acd5Sbostic #ifdef vax
417520acd5Sbostic 		/* For bug in ht driver. */
42*3aaddff2Skarels 		if (rcc > bsize)
43*3aaddff2Skarels 			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