1*df7f595eScegger /* $NetBSD: copy.c,v 1.14 2009/03/18 10:22:45 cegger Exp $ */
21564ce55Sperry
31564ce55Sperry /*-
41564ce55Sperry * Copyright (c) 1993
51564ce55Sperry * The Regents of the University of California. All rights reserved.
61564ce55Sperry *
71564ce55Sperry * Redistribution and use in source and binary forms, with or without
81564ce55Sperry * modification, are permitted provided that the following conditions
91564ce55Sperry * are met:
101564ce55Sperry * 1. Redistributions of source code must retain the above copyright
111564ce55Sperry * notice, this list of conditions and the following disclaimer.
121564ce55Sperry * 2. Redistributions in binary form must reproduce the above copyright
131564ce55Sperry * notice, this list of conditions and the following disclaimer in the
141564ce55Sperry * documentation and/or other materials provided with the distribution.
15aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
161564ce55Sperry * may be used to endorse or promote products derived from this software
171564ce55Sperry * without specific prior written permission.
181564ce55Sperry *
191564ce55Sperry * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201564ce55Sperry * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211564ce55Sperry * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221564ce55Sperry * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231564ce55Sperry * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241564ce55Sperry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251564ce55Sperry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261564ce55Sperry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271564ce55Sperry * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281564ce55Sperry * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291564ce55Sperry * SUCH DAMAGE.
301564ce55Sperry */
311564ce55Sperry
321564ce55Sperry #include <sys/cdefs.h>
331564ce55Sperry #ifndef lint
341564ce55Sperry __COPYRIGHT("@(#) Copyright (c) 1993\n\
351564ce55Sperry The Regents of the University of California. All rights reserved.\n");
361564ce55Sperry #endif /* not lint */
371564ce55Sperry
381564ce55Sperry #ifndef lint
391564ce55Sperry #if 0
401564ce55Sperry static char sccsid[] = "@(#)copy.c 8.1 (Berkeley) 6/11/93";
411564ce55Sperry #else
42*df7f595eScegger __RCSID("$NetBSD: copy.c,v 1.14 2009/03/18 10:22:45 cegger Exp $");
431564ce55Sperry #endif
441564ce55Sperry #endif /* not lint */
451564ce55Sperry
461564ce55Sperry #define BSIZE 10240
471564ce55Sperry
481564ce55Sperry /*
491564ce55Sperry * Copy from from to to. Intended for use in system installation.
501564ce55Sperry */
main(void)51*df7f595eScegger main(void)
521564ce55Sperry {
531564ce55Sperry extern int errno;
541564ce55Sperry register int from, to, record, rcc, wcc, bsize = BSIZE;
551564ce55Sperry char buf[BSIZE];
561564ce55Sperry
571564ce55Sperry from = getfile("From", 0);
581564ce55Sperry to = getfile("To", 1);
591564ce55Sperry for (record = 0;; ++record) {
601564ce55Sperry if (!(rcc = read(from, buf, bsize)))
611564ce55Sperry break;
621564ce55Sperry if (rcc < 0) {
631564ce55Sperry printf("Record %d: read error, errno=%d\n",
641564ce55Sperry record, errno);
651564ce55Sperry break;
661564ce55Sperry }
671564ce55Sperry if (rcc != bsize) {
681564ce55Sperry if (record == 0) {
691564ce55Sperry bsize = rcc;
701564ce55Sperry printf("Block size set from input; %d bytes\n",
711564ce55Sperry bsize);
721564ce55Sperry } else
731564ce55Sperry printf("Record %d: read short; expected %d, got %d\n",
741564ce55Sperry record, bsize, rcc);
751564ce55Sperry }
761564ce55Sperry #ifdef __vax__
771564ce55Sperry /* For bug in ht driver. */
781564ce55Sperry if (rcc > bsize)
791564ce55Sperry rcc = bsize;
801564ce55Sperry #endif
811564ce55Sperry if ((wcc = write(to, buf, rcc)) < 0) {
821564ce55Sperry printf("Record %d: write error: errno=%d\n",
831564ce55Sperry record, errno);
841564ce55Sperry break;
851564ce55Sperry }
861564ce55Sperry if (wcc < rcc) {
871564ce55Sperry printf("Record %d: write short; expected %d, got %d\n",
881564ce55Sperry record, rcc, wcc);
891564ce55Sperry break;
901564ce55Sperry }
911564ce55Sperry }
921564ce55Sperry printf("copy completed: %d records copied\n", record);
931564ce55Sperry }
94