1*d44b9aafSbostic /*- 2*d44b9aafSbostic * Copyright (c) 1982, 1986, 1988 The Regents of the University of California. 3*d44b9aafSbostic * All rights reserved. 4a8638090Smckusick * 5*d44b9aafSbostic * %sccs.include.redist.c% 6*d44b9aafSbostic * 7*d44b9aafSbostic * @(#)copy.c 7.6 (Berkeley) 05/03/91 8a8638090Smckusick */ 985fb39b8Ssam 107520acd5Sbostic #define BSIZE 10240 117520acd5Sbostic 1285fb39b8Ssam /* 137520acd5Sbostic * Copy from from to to. Intended for use in system installation. 1485fb39b8Ssam */ 1585fb39b8Ssam main() 1685fb39b8Ssam { 173af48ffbSsam extern int errno; 187520acd5Sbostic register int from, to, record, rcc, wcc; 197520acd5Sbostic char buf[BSIZE]; 2085fb39b8Ssam 21b103beccSbostic from = getfile("From", 0); 22b103beccSbostic to = getfile("To", 1); 237520acd5Sbostic for (record = 0;; ++record) { 247520acd5Sbostic if (!(rcc = read(from, buf, BSIZE))) 2585fb39b8Ssam break; 263af48ffbSsam if (rcc < 0) { 27089cce68Ssam printf("Record %d: read error, errno=%d\n", 28089cce68Ssam record, errno); 293af48ffbSsam break; 3085fb39b8Ssam } 317520acd5Sbostic if (!record && rcc != BSIZE) { 327520acd5Sbostic rcc = BSIZE; 337520acd5Sbostic printf("Block size set from input; %d bytes\n", BSIZE); 347520acd5Sbostic } 357520acd5Sbostic if (rcc < BSIZE) 363af48ffbSsam printf("Record %d: read short; expected %d, got %d\n", 377520acd5Sbostic record, BSIZE, rcc); 387520acd5Sbostic #ifdef vax 397520acd5Sbostic /* For bug in ht driver. */ 407520acd5Sbostic if (rcc > BSIZE) 417520acd5Sbostic rcc = BSIZE; 427520acd5Sbostic #endif 437520acd5Sbostic if ((wcc = write(to, buf, rcc)) < 0) { 44089cce68Ssam printf("Record %d: write error: errno=%d\n", 45089cce68Ssam record, errno); 463af48ffbSsam break; 473af48ffbSsam } 48b9d511d3Ssam if (wcc < rcc) { 49089cce68Ssam printf("Record %d: write short; expected %d, got %d\n", 50089cce68Ssam record, rcc, wcc); 513af48ffbSsam break; 523af48ffbSsam } 533af48ffbSsam } 547520acd5Sbostic printf("copy completed: %d records copied\n", record); 5585fb39b8Ssam } 56