1 /* 2 * Copyright (c) 1982, 1986, 1988 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)copy.c 7.5 (Berkeley) 05/24/88 7 */ 8 9 #define BSIZE 10240 10 11 /* 12 * Copy from from to to. Intended for use in system installation. 13 */ 14 main() 15 { 16 extern int errno; 17 register int from, to, record, rcc, wcc; 18 char buf[BSIZE]; 19 20 from = getfile("From", 0); 21 to = getfile("To", 1); 22 for (record = 0;; ++record) { 23 if (!(rcc = read(from, buf, BSIZE))) 24 break; 25 if (rcc < 0) { 26 printf("Record %d: read error, errno=%d\n", 27 record, errno); 28 break; 29 } 30 if (!record && rcc != BSIZE) { 31 rcc = BSIZE; 32 printf("Block size set from input; %d bytes\n", BSIZE); 33 } 34 if (rcc < BSIZE) 35 printf("Record %d: read short; expected %d, got %d\n", 36 record, BSIZE, rcc); 37 #ifdef vax 38 /* For bug in ht driver. */ 39 if (rcc > BSIZE) 40 rcc = BSIZE; 41 #endif 42 if ((wcc = write(to, buf, rcc)) < 0) { 43 printf("Record %d: write error: errno=%d\n", 44 record, errno); 45 break; 46 } 47 if (wcc < rcc) { 48 printf("Record %d: write short; expected %d, got %d\n", 49 record, rcc, wcc); 50 break; 51 } 52 } 53 printf("copy completed: %d records copied\n", record); 54 } 55