|
|
1.1 root 1: /*
2: * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution is only permitted until one year after the first shipment
6: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
7: * binary forms are permitted provided that: (1) source distributions retain
8: * this entire copyright notice and comment, and (2) distributions including
9: * binaries display the following acknowledgement: This product includes
10: * software developed by the University of California, Berkeley and its
11: * contributors'' in the documentation or other materials provided with the
12: * distribution and in all advertising materials mentioning features or use
13: * of this software. Neither the name of the University nor the names of
14: * its contributors may be used to endorse or promote products derived from
15: * this software without specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: *
20: * @(#)copy.c 7.1 (Berkeley) 5/8/90
21: */
22:
23: /*
24: * Copy from to in 10K units.
25: * Intended for use in system
26: * installation.
27: */
28: main()
29: {
30: int from, to;
31: char fbuf[50], tbuf[50];
32: char buffer[10240];
33: register int record;
34: extern int errno;
35:
36: from = getdev("From", fbuf, 0);
37: to = getdev("To", tbuf, 1);
38: for (record = 0; ; record++) {
39: int rcc, wcc;
40:
41: rcc = read(from, buffer, sizeof (buffer));
42: if (rcc == 0)
43: break;
44: if (rcc < 0) {
45: printf("Record %d: read error, errno=%d\n",
46: record, errno);
47: break;
48: }
49: if (rcc < sizeof (buffer))
50: printf("Record %d: read short; expected %d, got %d\n",
51: record, sizeof (buffer), rcc);
52: /*
53: * For bug in ht driver.
54: */
55: if (rcc > sizeof (buffer))
56: rcc = sizeof (buffer);
57: wcc = write(to, buffer, rcc);
58: if (wcc < 0) {
59: printf("Record %d: write error: errno=%d\n",
60: record, errno);
61: break;
62: }
63: if (wcc < rcc) {
64: printf("Record %d: write short; expected %d, got %d\n",
65: record, rcc, wcc);
66: break;
67: }
68: }
69: printf("Copy completed: %d records copied\n", record);
70: /* can't call exit here */
71: }
72:
73: getdev(prompt, buf, mode)
74: char *prompt, *buf;
75: int mode;
76: {
77: register int i;
78:
79: do {
80: printf("%s: ", prompt);
81: gets(buf);
82: i = open(buf, mode);
83: } while (i <= 0);
84: return (i);
85: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.