Commit | Line | Data |
---|---|---|
8ae0e4b4 | 1 | /* |
0880b18e | 2 | * Copyright (c) 1982, 1986 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 | * | |
0880b18e | 6 | * @(#)copy.c 7.1 (Berkeley) %G% |
8ae0e4b4 | 7 | */ |
4fb3673c SL |
8 | |
9 | /* | |
10 | * Copy from to in 10K units. | |
11 | * Intended for use in system | |
12 | * installation. | |
13 | */ | |
14 | main() | |
15 | { | |
16 | int from, to; | |
17 | char fbuf[50], tbuf[50]; | |
18 | char buffer[10240]; | |
b8e44ba3 SL |
19 | register int record; |
20 | extern int errno; | |
4fb3673c SL |
21 | |
22 | from = getdev("From", fbuf, 0); | |
23 | to = getdev("To", tbuf, 1); | |
b8e44ba3 SL |
24 | for (record = 0; ; record++) { |
25 | int rcc, wcc; | |
26 | ||
27 | rcc = read(from, buffer, sizeof (buffer)); | |
28 | if (rcc == 0) | |
29 | break; | |
30 | if (rcc < 0) { | |
475e1bcd SL |
31 | printf("Record %d: read error, errno=%d\n", |
32 | record, errno); | |
b8e44ba3 SL |
33 | break; |
34 | } | |
dcfb5891 | 35 | if (rcc < sizeof (buffer)) |
b8e44ba3 | 36 | printf("Record %d: read short; expected %d, got %d\n", |
475e1bcd | 37 | record, sizeof (buffer), rcc); |
d0e1e528 SL |
38 | /* |
39 | * For bug in ht driver. | |
40 | */ | |
41 | if (rcc > sizeof (buffer)) | |
42 | rcc = sizeof (buffer); | |
b8e44ba3 SL |
43 | wcc = write(to, buffer, rcc); |
44 | if (wcc < 0) { | |
475e1bcd SL |
45 | printf("Record %d: write error: errno=%d\n", |
46 | record, errno); | |
b8e44ba3 SL |
47 | break; |
48 | } | |
dcfb5891 | 49 | if (wcc < rcc) { |
475e1bcd SL |
50 | printf("Record %d: write short; expected %d, got %d\n", |
51 | record, rcc, wcc); | |
4fb3673c | 52 | break; |
b8e44ba3 | 53 | } |
4fb3673c | 54 | } |
b8e44ba3 | 55 | printf("Copy completed: %d records copied\n", record); |
4fb3673c SL |
56 | /* can't call exit here */ |
57 | } | |
58 | ||
59 | getdev(prompt, buf, mode) | |
60 | char *prompt, *buf; | |
61 | int mode; | |
62 | { | |
63 | register int i; | |
64 | ||
65 | do { | |
66 | printf("%s: ", prompt); | |
67 | gets(buf); | |
68 | i = open(buf, mode); | |
69 | } while (i <= 0); | |
70 | return (i); | |
71 | } |