1 /* 2 * Copyright (c) 1982, 1986 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.4 (Berkeley) 02/23/88 7 */ 8 9 /* 10 * Copy from to in 10K units. 11 * Intended for use in system 12 * installation. 13 */ 14 main() 15 { 16 extern int errno; 17 register int from, to, record; 18 char buffer[10240]; 19 20 from = getfile("From", 0); 21 to = getfile("To", 1); 22 for (record = 0; ; record++) { 23 register int rcc, wcc; 24 25 rcc = read(from, buffer, sizeof (buffer)); 26 if (rcc == 0) 27 break; 28 if (rcc < 0) { 29 printf("Record %d: read error, errno=%d\n", 30 record, errno); 31 break; 32 } 33 if (rcc < sizeof (buffer)) 34 printf("Record %d: read short; expected %d, got %d\n", 35 record, sizeof (buffer), rcc); 36 /* 37 * For bug in ht driver. 38 */ 39 if (rcc > sizeof (buffer)) 40 rcc = sizeof (buffer); 41 wcc = write(to, buffer, rcc); 42 if (wcc < 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 /* can't call exit here */ 55 } 56