xref: /csrg-svn/sys/stand.att/docopy.c (revision 33641)
1*33641Sbostic /*
2*33641Sbostic  * Copyright (c) 1988 Regents of the University of California.
3*33641Sbostic  * All rights reserved.
4*33641Sbostic  *
5*33641Sbostic  * Redistribution and use in source and binary forms are permitted
6*33641Sbostic  * provided that this notice is preserved and that due credit is given
7*33641Sbostic  * to the University of California at Berkeley. The name of the University
8*33641Sbostic  * may not be used to endorse or promote products derived from this
9*33641Sbostic  * software without specific prior written permission. This software
10*33641Sbostic  * is provided ``as is'' without express or implied warranty.
11*33641Sbostic  *
12*33641Sbostic  *	@(#)docopy.c	7.1 (Berkeley) 03/03/88
13*33641Sbostic  */
14*33641Sbostic #define	SIZE	10240
15*33641Sbostic 
16*33641Sbostic docopy(from, to, nrecs)
17*33641Sbostic 	register int from, to, nrecs;
18*33641Sbostic {
19*33641Sbostic 	register int record, rcc, wcc;
20*33641Sbostic 	char buf[SIZE];
21*33641Sbostic 
22*33641Sbostic 	for (record = 0;;) {
23*33641Sbostic 		if (!(rcc = read(from, buffer, SIZE)))
24*33641Sbostic 			break;
25*33641Sbostic 		if (rcc < 0) {
26*33641Sbostic 			printf("Record %d: read error, errno=%d\n",
27*33641Sbostic 			    record, errno);
28*33641Sbostic 			break;
29*33641Sbostic 		}
30*33641Sbostic 		if (rcc < SIZE)
31*33641Sbostic 			printf("Record %d: read short; expected %d, got %d\n",
32*33641Sbostic 			    record, SIZE, rcc);
33*33641Sbostic #ifdef vax
34*33641Sbostic 		/* For bug in ht driver. */
35*33641Sbostic 		if (rcc > SIZE)
36*33641Sbostic 			rcc = SIZE;
37*33641Sbostic #endif
38*33641Sbostic 		if ((wcc = write(to, buffer, rcc)) < 0) {
39*33641Sbostic 			printf("Record %d: write error: errno=%d\n",
40*33641Sbostic 			    record, errno);
41*33641Sbostic 			break;
42*33641Sbostic 		}
43*33641Sbostic 		if (wcc < rcc) {
44*33641Sbostic 			printf("Record %d: write short; expected %d, got %d\n",
45*33641Sbostic 			    record, rcc, wcc);
46*33641Sbostic 			break;
47*33641Sbostic 		}
48*33641Sbostic 		if (nrecs > 0 && ++record == nrecs)
49*33641Sbostic 			break;
50*33641Sbostic 	}
51*33641Sbostic 	printf("copy completed: %d records copied\n", record);
52*33641Sbostic }
53