Commit | Line | Data |
---|---|---|
54df343c MK |
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 1.1 (Berkeley) %G% | |
7 | */ | |
8 | ||
9 | /* | |
10 | * Copy from to in 10K units. | |
11 | * Intended for use in system | |
12 | * installation. | |
13 | */ | |
14 | char buffer[32*1024]; | |
15 | ||
16 | main() | |
17 | { | |
18 | int from, to, firstrecord = 1; | |
19 | char fbuf[50], tbuf[50]; | |
20 | register int record, recsize = sizeof (buffer); | |
21 | extern int errno; | |
22 | ||
23 | from = getdev("From", fbuf, 0); | |
24 | to = getdev("To", tbuf, 1); | |
25 | for (record = 0; ; record++) { | |
26 | int rcc, wcc; | |
27 | ||
28 | /* printf("read(%d, %x, %d)\n", from, buffer, recsize); */ | |
29 | rcc = read(from, buffer, recsize); | |
30 | /* printf("rcc %d\n", rcc); */ | |
31 | if (rcc == 0) | |
32 | break; | |
33 | if (rcc < 0) { | |
34 | printf("Record %d: read error, errno=%d\n", | |
35 | record, errno); | |
36 | break; | |
37 | } | |
38 | if (firstrecord) { | |
39 | if (rcc != recsize) | |
40 | recsize = rcc; | |
41 | firstrecord = !firstrecord; | |
42 | printf("%d Kbyte records\n", recsize/1024); | |
43 | } | |
44 | if (rcc < recsize) | |
45 | printf("Record %d: read short; expected %d, got %d\n", | |
46 | record, sizeof (buffer), rcc); | |
47 | wcc = write(to, buffer, rcc); | |
48 | if (wcc < 0) { | |
49 | printf("Record %d: write error: errno=%d\n", | |
50 | record, errno); | |
51 | break; | |
52 | } | |
53 | if (wcc < rcc) { | |
54 | printf("Record %d: write short; expected %d, got %d\n", | |
55 | record, rcc, wcc); | |
56 | break; | |
57 | } | |
58 | } | |
59 | printf("%d records copied\n", record); | |
60 | /* can't call exit here */ | |
61 | } | |
62 | ||
63 | getdev(prompt, buf, mode) | |
64 | char *prompt, *buf; | |
65 | int mode; | |
66 | { | |
67 | register int i; | |
68 | ||
69 | do { | |
70 | printf("%s: ", prompt); | |
71 | gets(buf); | |
72 | i = open(buf, mode); | |
73 | } while (i <= 0); | |
74 | return (i); | |
75 | } |