1*a8638090Smckusick /* 2*a8638090Smckusick * Copyright (c) 1982 Regents of the University of California. 3*a8638090Smckusick * All rights reserved. The Berkeley software License Agreement 4*a8638090Smckusick * specifies the terms and conditions for redistribution. 5*a8638090Smckusick * 6*a8638090Smckusick * @(#)copy.c 6.2 (Berkeley) 06/08/85 7*a8638090Smckusick */ 885fb39b8Ssam 985fb39b8Ssam /* 1085fb39b8Ssam * Copy from to in 10K units. 1185fb39b8Ssam * Intended for use in system 1285fb39b8Ssam * installation. 1385fb39b8Ssam */ 1485fb39b8Ssam main() 1585fb39b8Ssam { 1685fb39b8Ssam int from, to; 1785fb39b8Ssam char fbuf[50], tbuf[50]; 1885fb39b8Ssam char buffer[10240]; 193af48ffbSsam register int record; 203af48ffbSsam extern int errno; 2185fb39b8Ssam 2285fb39b8Ssam from = getdev("From", fbuf, 0); 2385fb39b8Ssam to = getdev("To", tbuf, 1); 243af48ffbSsam for (record = 0; ; record++) { 253af48ffbSsam int rcc, wcc; 263af48ffbSsam 273af48ffbSsam rcc = read(from, buffer, sizeof (buffer)); 283af48ffbSsam if (rcc == 0) 2985fb39b8Ssam break; 303af48ffbSsam if (rcc < 0) { 31089cce68Ssam printf("Record %d: read error, errno=%d\n", 32089cce68Ssam record, errno); 333af48ffbSsam break; 3485fb39b8Ssam } 35b9d511d3Ssam if (rcc < sizeof (buffer)) 363af48ffbSsam printf("Record %d: read short; expected %d, got %d\n", 37089cce68Ssam record, sizeof (buffer), rcc); 38c235ae49Ssam /* 39c235ae49Ssam * For bug in ht driver. 40c235ae49Ssam */ 41c235ae49Ssam if (rcc > sizeof (buffer)) 42c235ae49Ssam rcc = sizeof (buffer); 433af48ffbSsam wcc = write(to, buffer, rcc); 443af48ffbSsam if (wcc < 0) { 45089cce68Ssam printf("Record %d: write error: errno=%d\n", 46089cce68Ssam record, errno); 473af48ffbSsam break; 483af48ffbSsam } 49b9d511d3Ssam if (wcc < rcc) { 50089cce68Ssam printf("Record %d: write short; expected %d, got %d\n", 51089cce68Ssam record, rcc, wcc); 523af48ffbSsam break; 533af48ffbSsam } 543af48ffbSsam } 553af48ffbSsam printf("Copy completed: %d records copied\n", record); 5685fb39b8Ssam /* can't call exit here */ 5785fb39b8Ssam } 5885fb39b8Ssam 5985fb39b8Ssam getdev(prompt, buf, mode) 6085fb39b8Ssam char *prompt, *buf; 6185fb39b8Ssam int mode; 6285fb39b8Ssam { 6385fb39b8Ssam register int i; 6485fb39b8Ssam 6585fb39b8Ssam do { 6685fb39b8Ssam printf("%s: ", prompt); 6785fb39b8Ssam gets(buf); 6885fb39b8Ssam i = open(buf, mode); 6985fb39b8Ssam } while (i <= 0); 7085fb39b8Ssam return (i); 7185fb39b8Ssam } 72