1 /* 2 * Copyright (c) 1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)docopy.c 7.3 (Berkeley) 06/28/90 8 */ 9 10 #define SIZE 10240 11 12 docopy(from, to, nrecs) 13 register int from, to, nrecs; 14 { 15 register int record, rcc, wcc; 16 char buf[SIZE]; 17 18 for (record = 0;;) { 19 if (!(rcc = read(from, buffer, SIZE))) 20 break; 21 if (rcc < 0) { 22 printf("Record %d: read error, errno=%d\n", 23 record, errno); 24 break; 25 } 26 if (rcc < SIZE) 27 printf("Record %d: read short; expected %d, got %d\n", 28 record, SIZE, rcc); 29 #ifdef vax 30 /* For bug in ht driver. */ 31 if (rcc > SIZE) 32 rcc = SIZE; 33 #endif 34 if ((wcc = write(to, buffer, rcc)) < 0) { 35 printf("Record %d: write error: errno=%d\n", 36 record, errno); 37 break; 38 } 39 if (wcc < rcc) { 40 printf("Record %d: write short; expected %d, got %d\n", 41 record, rcc, wcc); 42 break; 43 } 44 if (nrecs > 0 && ++record == nrecs) 45 break; 46 } 47 printf("copy completed: %d records copied\n", record); 48 } 49