xref: /original-bsd/sys/stand.att/copy.c (revision 3af48ffb)
1*3af48ffbSsam /*	copy.c	4.2	83/02/16	*/
285fb39b8Ssam 
385fb39b8Ssam /*
485fb39b8Ssam  * Copy from to in 10K units.
585fb39b8Ssam  * Intended for use in system
685fb39b8Ssam  * installation.
785fb39b8Ssam  */
885fb39b8Ssam main()
985fb39b8Ssam {
1085fb39b8Ssam 	int from, to;
1185fb39b8Ssam 	char fbuf[50], tbuf[50];
1285fb39b8Ssam 	char buffer[10240];
13*3af48ffbSsam 	register int record;
14*3af48ffbSsam 	extern int errno;
1585fb39b8Ssam 
1685fb39b8Ssam 	from = getdev("From", fbuf, 0);
1785fb39b8Ssam 	to = getdev("To", tbuf, 1);
18*3af48ffbSsam 	for (record = 0; ; record++) {
19*3af48ffbSsam 		int rcc, wcc;
20*3af48ffbSsam 
21*3af48ffbSsam 		rcc = read(from, buffer, sizeof (buffer));
22*3af48ffbSsam 		if (rcc == 0)
2385fb39b8Ssam 			break;
24*3af48ffbSsam 		if (rcc < 0) {
25*3af48ffbSsam 			printf("Read error, errno=%d\n", errno);
26*3af48ffbSsam 			break;
2785fb39b8Ssam 		}
28*3af48ffbSsam 		if (rcc != sizeof (buffer))
29*3af48ffbSsam 			printf("Record %d: read short; expected %d, got %d\n",
30*3af48ffbSsam 				sizeof (buffer), rcc);
31*3af48ffbSsam 		wcc = write(to, buffer, rcc);
32*3af48ffbSsam 		if (wcc < 0) {
33*3af48ffbSsam 			printf("Write error: errno=%d\n", errno);
34*3af48ffbSsam 			break;
35*3af48ffbSsam 		}
36*3af48ffbSsam 		if (wcc != rcc) {
37*3af48ffbSsam 			printf("Write short; expected %d, got %d\n", rcc, wcc);
38*3af48ffbSsam 			break;
39*3af48ffbSsam 		}
40*3af48ffbSsam 	}
41*3af48ffbSsam 	printf("Copy completed: %d records copied\n", record);
4285fb39b8Ssam 	/* can't call exit here */
4385fb39b8Ssam }
4485fb39b8Ssam 
4585fb39b8Ssam getdev(prompt, buf, mode)
4685fb39b8Ssam 	char *prompt, *buf;
4785fb39b8Ssam 	int mode;
4885fb39b8Ssam {
4985fb39b8Ssam 	register int i;
5085fb39b8Ssam 
5185fb39b8Ssam 	do {
5285fb39b8Ssam 		printf("%s: ", prompt);
5385fb39b8Ssam 		gets(buf);
5485fb39b8Ssam 		i = open(buf, mode);
5585fb39b8Ssam 	} while (i <= 0);
5685fb39b8Ssam 	return (i);
5785fb39b8Ssam }
58