Commit | Line | Data |
---|---|---|
475e1bcd | 1 | /* copy.c 4.3 83/02/18 */ |
4fb3673c SL |
2 | |
3 | /* | |
4 | * Copy from to in 10K units. | |
5 | * Intended for use in system | |
6 | * installation. | |
7 | */ | |
8 | main() | |
9 | { | |
10 | int from, to; | |
11 | char fbuf[50], tbuf[50]; | |
12 | char buffer[10240]; | |
b8e44ba3 SL |
13 | register int record; |
14 | extern int errno; | |
4fb3673c SL |
15 | |
16 | from = getdev("From", fbuf, 0); | |
17 | to = getdev("To", tbuf, 1); | |
b8e44ba3 SL |
18 | for (record = 0; ; record++) { |
19 | int rcc, wcc; | |
20 | ||
21 | rcc = read(from, buffer, sizeof (buffer)); | |
22 | if (rcc == 0) | |
23 | break; | |
24 | if (rcc < 0) { | |
475e1bcd SL |
25 | printf("Record %d: read error, errno=%d\n", |
26 | record, errno); | |
b8e44ba3 SL |
27 | break; |
28 | } | |
29 | if (rcc != sizeof (buffer)) | |
30 | printf("Record %d: read short; expected %d, got %d\n", | |
475e1bcd | 31 | record, sizeof (buffer), rcc); |
b8e44ba3 SL |
32 | wcc = write(to, buffer, rcc); |
33 | if (wcc < 0) { | |
475e1bcd SL |
34 | printf("Record %d: write error: errno=%d\n", |
35 | record, errno); | |
b8e44ba3 SL |
36 | break; |
37 | } | |
38 | if (wcc != rcc) { | |
475e1bcd SL |
39 | printf("Record %d: write short; expected %d, got %d\n", |
40 | record, rcc, wcc); | |
4fb3673c | 41 | break; |
b8e44ba3 | 42 | } |
4fb3673c | 43 | } |
b8e44ba3 | 44 | printf("Copy completed: %d records copied\n", record); |
4fb3673c SL |
45 | /* can't call exit here */ |
46 | } | |
47 | ||
48 | getdev(prompt, buf, mode) | |
49 | char *prompt, *buf; | |
50 | int mode; | |
51 | { | |
52 | register int i; | |
53 | ||
54 | do { | |
55 | printf("%s: ", prompt); | |
56 | gets(buf); | |
57 | i = open(buf, mode); | |
58 | } while (i <= 0); | |
59 | return (i); | |
60 | } |