date and time created 88/07/22 16:08:01 by bostic
[unix-history] / usr / src / sys / stand.att / copy.c
index 0883fd3..faead5b 100644 (file)
@@ -1,55 +1,54 @@
 /*
 /*
- * Copyright (c) 1982, 1986 Regents of the University of California.
+ * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  *     @(#)copy.c      7.5 (Berkeley) %G%
  */
 
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  *     @(#)copy.c      7.5 (Berkeley) %G%
  */
 
+#define        BSIZE   10240
+
 /*
 /*
- * Copy from to in 10K units.
- * Intended for use in system
- * installation.
+ * Copy from from to to.  Intended for use in system installation.
  */
 main()
 {
        extern int errno;
  */
 main()
 {
        extern int errno;
-       register int from, to, record;
-       char buffer[10240];
+       register int from, to, record, rcc, wcc;
+       char buf[BSIZE];
 
        from = getfile("From", 0);
        to = getfile("To", 1);
 
        from = getfile("From", 0);
        to = getfile("To", 1);
-       for (record = 0; ; record++) {
-               register int rcc, wcc;
-
-               rcc = read(from, buffer, sizeof (buffer));
-               if (rcc == 0)
+       for (record = 0;; ++record) {
+               if (!(rcc = read(from, buf, BSIZE)))
                        break;
                if (rcc < 0) {
                        printf("Record %d: read error, errno=%d\n",
                        break;
                if (rcc < 0) {
                        printf("Record %d: read error, errno=%d\n",
-                               record, errno);
+                           record, errno);
                        break;
                }
                        break;
                }
-               if (rcc < sizeof (buffer))
+               if (!record && rcc != BSIZE) {
+                       rcc = BSIZE;
+                       printf("Block size set from input; %d bytes\n", BSIZE);
+               }
+               if (rcc < BSIZE)
                        printf("Record %d: read short; expected %d, got %d\n",
                        printf("Record %d: read short; expected %d, got %d\n",
-                               record, sizeof (buffer), rcc);
-               /*
-                * For bug in ht driver.
-                */
-               if (rcc > sizeof (buffer))
-                       rcc = sizeof (buffer);
-               wcc = write(to, buffer, rcc);
-               if (wcc < 0) {
+                           record, BSIZE, rcc);
+#ifdef vax
+               /* For bug in ht driver. */
+               if (rcc > BSIZE)
+                       rcc = BSIZE;
+#endif
+               if ((wcc = write(to, buf, rcc)) < 0) {
                        printf("Record %d: write error: errno=%d\n",
                        printf("Record %d: write error: errno=%d\n",
-                               record, errno);
+                           record, errno);
                        break;
                }
                if (wcc < rcc) {
                        printf("Record %d: write short; expected %d, got %d\n",
                        break;
                }
                if (wcc < rcc) {
                        printf("Record %d: write short; expected %d, got %d\n",
-                               record, rcc, wcc);
+                           record, rcc, wcc);
                        break;
                }
        }
                        break;
                }
        }
-       printf("Copy completed: %d records copied\n", record);
-       /* can't call exit here */
+       printf("copy completed: %d records copied\n", record);
 }
 }