148978Sbostic /*-
2*63370Sbostic * Copyright (c) 1982, 1986, 1988, 1993
3*63370Sbostic * The Regents of the University of California. All rights reserved.
423223Smckusick *
548978Sbostic * %sccs.include.redist.c%
648978Sbostic *
7*63370Sbostic * @(#)copy.c 8.1 (Berkeley) 06/11/93
823223Smckusick */
911052Ssam
1034464Sbostic #define BSIZE 10240
1134464Sbostic
1211052Ssam /*
1334464Sbostic * Copy from from to to. Intended for use in system installation.
1411052Ssam */
main()1511052Ssam main()
1611052Ssam {
1733544Sbostic extern int errno;
1849844Skarels register int from, to, record, rcc, wcc, bsize = BSIZE;
1934464Sbostic char buf[BSIZE];
2011052Ssam
2133544Sbostic from = getfile("From", 0);
2233544Sbostic to = getfile("To", 1);
2334464Sbostic for (record = 0;; ++record) {
2449844Skarels if (!(rcc = read(from, buf, bsize)))
2511052Ssam break;
2611081Ssam if (rcc < 0) {
2711135Ssam printf("Record %d: read error, errno=%d\n",
2834464Sbostic record, errno);
2911081Ssam break;
3011081Ssam }
3149844Skarels if (rcc != bsize) {
3249844Skarels if (record == 0) {
3349844Skarels bsize = rcc;
3449844Skarels printf("Block size set from input; %d bytes\n",
3549844Skarels bsize);
3649844Skarels } else
3749844Skarels printf("Record %d: read short; expected %d, got %d\n",
3849844Skarels record, bsize, rcc);
3934464Sbostic }
4034464Sbostic #ifdef vax
4134464Sbostic /* For bug in ht driver. */
4249844Skarels if (rcc > bsize)
4349844Skarels rcc = bsize;
4434464Sbostic #endif
4534464Sbostic if ((wcc = write(to, buf, rcc)) < 0) {
4611135Ssam printf("Record %d: write error: errno=%d\n",
4734464Sbostic record, errno);
4811081Ssam break;
4911081Ssam }
5011178Ssam if (wcc < rcc) {
5111135Ssam printf("Record %d: write short; expected %d, got %d\n",
5234464Sbostic record, rcc, wcc);
5311081Ssam break;
5411081Ssam }
5511052Ssam }
5634464Sbostic printf("copy completed: %d records copied\n", record);
5711052Ssam }
58