xref: /original-bsd/sys/stand.att/copy.c (revision de3f5c4e)
1 /*-
2  * Copyright (c) 1982, 1986, 1988 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)copy.c	7.6 (Berkeley) 05/03/91
8  */
9 
10 #define	BSIZE	10240
11 
12 /*
13  * Copy from from to to.  Intended for use in system installation.
14  */
15 main()
16 {
17 	extern int errno;
18 	register int from, to, record, rcc, wcc;
19 	char buf[BSIZE];
20 
21 	from = getfile("From", 0);
22 	to = getfile("To", 1);
23 	for (record = 0;; ++record) {
24 		if (!(rcc = read(from, buf, BSIZE)))
25 			break;
26 		if (rcc < 0) {
27 			printf("Record %d: read error, errno=%d\n",
28 			    record, errno);
29 			break;
30 		}
31 		if (!record && rcc != BSIZE) {
32 			rcc = BSIZE;
33 			printf("Block size set from input; %d bytes\n", BSIZE);
34 		}
35 		if (rcc < BSIZE)
36 			printf("Record %d: read short; expected %d, got %d\n",
37 			    record, BSIZE, rcc);
38 #ifdef vax
39 		/* For bug in ht driver. */
40 		if (rcc > BSIZE)
41 			rcc = BSIZE;
42 #endif
43 		if ((wcc = write(to, buf, rcc)) < 0) {
44 			printf("Record %d: write error: errno=%d\n",
45 			    record, errno);
46 			break;
47 		}
48 		if (wcc < rcc) {
49 			printf("Record %d: write short; expected %d, got %d\n",
50 			    record, rcc, wcc);
51 			break;
52 		}
53 	}
54 	printf("copy completed: %d records copied\n", record);
55 }
56