xref: /csrg-svn/sys/stand.att/copy.c (revision 11081)
1*11081Ssam /*	copy.c	4.2	83/02/16	*/
211052Ssam 
311052Ssam /*
411052Ssam  * Copy from to in 10K units.
511052Ssam  * Intended for use in system
611052Ssam  * installation.
711052Ssam  */
811052Ssam main()
911052Ssam {
1011052Ssam 	int from, to;
1111052Ssam 	char fbuf[50], tbuf[50];
1211052Ssam 	char buffer[10240];
13*11081Ssam 	register int record;
14*11081Ssam 	extern int errno;
1511052Ssam 
1611052Ssam 	from = getdev("From", fbuf, 0);
1711052Ssam 	to = getdev("To", tbuf, 1);
18*11081Ssam 	for (record = 0; ; record++) {
19*11081Ssam 		int rcc, wcc;
20*11081Ssam 
21*11081Ssam 		rcc = read(from, buffer, sizeof (buffer));
22*11081Ssam 		if (rcc == 0)
2311052Ssam 			break;
24*11081Ssam 		if (rcc < 0) {
25*11081Ssam 			printf("Read error, errno=%d\n", errno);
26*11081Ssam 			break;
27*11081Ssam 		}
28*11081Ssam 		if (rcc != sizeof (buffer))
29*11081Ssam 			printf("Record %d: read short; expected %d, got %d\n",
30*11081Ssam 				sizeof (buffer), rcc);
31*11081Ssam 		wcc = write(to, buffer, rcc);
32*11081Ssam 		if (wcc < 0) {
33*11081Ssam 			printf("Write error: errno=%d\n", errno);
34*11081Ssam 			break;
35*11081Ssam 		}
36*11081Ssam 		if (wcc != rcc) {
37*11081Ssam 			printf("Write short; expected %d, got %d\n", rcc, wcc);
38*11081Ssam 			break;
39*11081Ssam 		}
4011052Ssam 	}
41*11081Ssam 	printf("Copy completed: %d records copied\n", record);
4211052Ssam 	/* can't call exit here */
4311052Ssam }
4411052Ssam 
4511052Ssam getdev(prompt, buf, mode)
4611052Ssam 	char *prompt, *buf;
4711052Ssam 	int mode;
4811052Ssam {
4911052Ssam 	register int i;
5011052Ssam 
5111052Ssam 	do {
5211052Ssam 		printf("%s: ", prompt);
5311052Ssam 		gets(buf);
5411052Ssam 		i = open(buf, mode);
5511052Ssam 	} while (i <= 0);
5611052Ssam 	return (i);
5711052Ssam }
58