Commit | Line | Data |
---|---|---|
8ae0e4b4 | 1 | /* |
dbd73061 | 2 | * Copyright (c) 1982, 1986, 1988 Regents of the University of California. |
8ae0e4b4 KM |
3 | * All rights reserved. The Berkeley software License Agreement |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
777c02a3 | 6 | * @(#)copy.c 7.5 (Berkeley) %G% |
8ae0e4b4 | 7 | */ |
4fb3673c | 8 | |
dbd73061 KB |
9 | #define BSIZE 10240 |
10 | ||
4fb3673c | 11 | /* |
dbd73061 | 12 | * Copy from from to to. Intended for use in system installation. |
4fb3673c SL |
13 | */ |
14 | main() | |
15 | { | |
b8e44ba3 | 16 | extern int errno; |
dbd73061 KB |
17 | register int from, to, record, rcc, wcc; |
18 | char buf[BSIZE]; | |
4fb3673c | 19 | |
74a847d1 KB |
20 | from = getfile("From", 0); |
21 | to = getfile("To", 1); | |
dbd73061 KB |
22 | for (record = 0;; ++record) { |
23 | if (!(rcc = read(from, buf, BSIZE))) | |
b8e44ba3 SL |
24 | break; |
25 | if (rcc < 0) { | |
475e1bcd | 26 | printf("Record %d: read error, errno=%d\n", |
dbd73061 | 27 | record, errno); |
b8e44ba3 SL |
28 | break; |
29 | } | |
dbd73061 KB |
30 | if (!record && rcc != BSIZE) { |
31 | rcc = BSIZE; | |
32 | printf("Block size set from input; %d bytes\n", BSIZE); | |
33 | } | |
34 | if (rcc < BSIZE) | |
b8e44ba3 | 35 | printf("Record %d: read short; expected %d, got %d\n", |
dbd73061 KB |
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) { | |
475e1bcd | 43 | printf("Record %d: write error: errno=%d\n", |
dbd73061 | 44 | record, errno); |
b8e44ba3 SL |
45 | break; |
46 | } | |
dcfb5891 | 47 | if (wcc < rcc) { |
475e1bcd | 48 | printf("Record %d: write short; expected %d, got %d\n", |
dbd73061 | 49 | record, rcc, wcc); |
4fb3673c | 50 | break; |
b8e44ba3 | 51 | } |
4fb3673c | 52 | } |
dbd73061 | 53 | printf("copy completed: %d records copied\n", record); |
4fb3673c | 54 | } |