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