xref: /csrg-svn/sys/stand.att/docopy.c (revision 44516)
133641Sbostic /*
233641Sbostic  * Copyright (c) 1988 Regents of the University of California.
333641Sbostic  * All rights reserved.
433641Sbostic  *
5*44516Sbostic  * %sccs.include.redist.c%
633641Sbostic  *
7*44516Sbostic  *	@(#)docopy.c	7.3 (Berkeley) 06/28/90
833641Sbostic  */
934871Sbostic 
1033641Sbostic #define	SIZE	10240
1133641Sbostic 
docopy(from,to,nrecs)1233641Sbostic docopy(from, to, nrecs)
1333641Sbostic 	register int from, to, nrecs;
1433641Sbostic {
1533641Sbostic 	register int record, rcc, wcc;
1633641Sbostic 	char buf[SIZE];
1733641Sbostic 
1833641Sbostic 	for (record = 0;;) {
1933641Sbostic 		if (!(rcc = read(from, buffer, SIZE)))
2033641Sbostic 			break;
2133641Sbostic 		if (rcc < 0) {
2233641Sbostic 			printf("Record %d: read error, errno=%d\n",
2333641Sbostic 			    record, errno);
2433641Sbostic 			break;
2533641Sbostic 		}
2633641Sbostic 		if (rcc < SIZE)
2733641Sbostic 			printf("Record %d: read short; expected %d, got %d\n",
2833641Sbostic 			    record, SIZE, rcc);
2933641Sbostic #ifdef vax
3033641Sbostic 		/* For bug in ht driver. */
3133641Sbostic 		if (rcc > SIZE)
3233641Sbostic 			rcc = SIZE;
3333641Sbostic #endif
3433641Sbostic 		if ((wcc = write(to, buffer, rcc)) < 0) {
3533641Sbostic 			printf("Record %d: write error: errno=%d\n",
3633641Sbostic 			    record, errno);
3733641Sbostic 			break;
3833641Sbostic 		}
3933641Sbostic 		if (wcc < rcc) {
4033641Sbostic 			printf("Record %d: write short; expected %d, got %d\n",
4133641Sbostic 			    record, rcc, wcc);
4233641Sbostic 			break;
4333641Sbostic 		}
4433641Sbostic 		if (nrecs > 0 && ++record == nrecs)
4533641Sbostic 			break;
4633641Sbostic 	}
4733641Sbostic 	printf("copy completed: %d records copied\n", record);
4833641Sbostic }
49