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.1 (Berkeley) 6/5/86
7: */
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];
19: register int record;
20: extern int errno;
21:
22: from = getdev("From", fbuf, 0);
23: to = getdev("To", tbuf, 1);
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) {
31: printf("Record %d: read error, errno=%d\n",
32: record, errno);
33: break;
34: }
35: if (rcc < sizeof (buffer))
36: printf("Record %d: read short; expected %d, got %d\n",
37: record, sizeof (buffer), rcc);
38: /*
39: * For bug in ht driver.
40: */
41: if (rcc > sizeof (buffer))
42: rcc = sizeof (buffer);
43: wcc = write(to, buffer, rcc);
44: if (wcc < 0) {
45: printf("Record %d: write error: errno=%d\n",
46: record, errno);
47: break;
48: }
49: if (wcc < rcc) {
50: printf("Record %d: write short; expected %d, got %d\n",
51: record, rcc, wcc);
52: break;
53: }
54: }
55: printf("Copy completed: %d records copied\n", record);
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: }
Defined functions
main
defined in line
14;
never used