1: /*
   2:  * Copyright (c) 1985 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: 
   7: #if defined(DOSCCS) && !defined(lint)
   8: char copyright[] =
   9: "@(#) Copyright (c) 1985 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: 
  12: static char sccsid[] = "@(#)tcopy.c	1.4 (2.11BSD GTE) 1996/6/4";
  13: #endif
  14: 
  15: #include <stdio.h>
  16: #include <signal.h>
  17: #include <sys/file.h>
  18: #include <sys/types.h>
  19: #include <sys/ioctl.h>
  20: #include <sys/mtio.h>
  21: #include <string.h>
  22: #include <errno.h>
  23: 
  24: #define SIZE    ((unsigned)32 * 1024)
  25: 
  26: char buff[SIZE];
  27: int filen=1;
  28: long count, lcount;
  29: int RUBOUT();
  30: int nfile;
  31: long size, tsize;
  32: int ln;
  33: char *inf, *outf;
  34: int copy;
  35: static char *msg1= "file %d: records %ld to %ld: size %u\n";
  36: static char *msg2 = "file %d: record %ld: size %u\n";
  37: 
  38: main(argc, argv)
  39: char **argv;
  40: {
  41:     register n, nw, inp, outp;
  42:     struct mtop op;
  43: 
  44:     if (argc <=1 || argc > 3) {
  45:         fprintf(stderr, "Usage: tcopy src [dest]\n");
  46:         exit(1);
  47:     }
  48:     inf = argv[1];
  49:     if (argc == 3) {
  50:         outf = argv[2];
  51:         copy = 1;
  52:     }
  53:     if ((inp=open(inf, O_RDONLY, 0666)) < 0)
  54:         err(1, "Can't open %s", inf);
  55: 
  56:     if (copy) {
  57:         if ((outp=open(outf, O_WRONLY, 0666)) < 0)
  58:             err(3, "Can't open %s", outf);
  59:     }
  60:     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  61:         (void) signal(SIGINT, RUBOUT);
  62:     ln = -2;
  63:     for (;;) {
  64:         count++;
  65:         n = read(inp, buff, SIZE);
  66:         if (n > 0) {
  67:             nw = write(outp, buff, n);
  68:             if (copy) {
  69:                 if (nw != n) {
  70:                 int error = errno;
  71:                 if (nw == -1)
  72:                     fprintf(stderr, "write error, file %d, record %ld: ",
  73:                         filen, lcount);
  74:                 if (nw == -1)
  75:                     fprintf(stderr, "%s",strerror(error));
  76:                 else
  77:                     fprintf(stderr,
  78:                         "write (%u) != read (%u)\n",
  79:                         nw, n);
  80:                 fprintf(stderr, "copy aborted\n");
  81:                 exit(5);
  82:                 }
  83:             }
  84:             size += n;
  85:             if (n != ln) {
  86:             if (ln > 0)
  87:                 if (count - lcount > 1)
  88:                 printf(msg1, filen, lcount, count-1, ln);
  89:                 else
  90:                 printf(msg2, filen, lcount, ln);
  91:             ln = n;
  92:             lcount = count;
  93:             }
  94:         }
  95:         else {
  96:             if (ln <= 0 && ln != -2) {
  97:                 printf("eot\n");
  98:                 break;
  99:             }
 100:             if (ln > 0)
 101:                 if (count - lcount > 1)
 102:                 printf(msg1, filen, lcount, count-1, ln);
 103:                 else
 104:                 printf(msg2, filen, lcount, ln);
 105:             printf("file %d: eof after %ld records: %ld bytes\n",
 106:                 filen, count-1, size);
 107:             if (copy) {
 108:                 op.mt_op = MTWEOF;
 109:                 op.mt_count = (daddr_t)1;
 110:                 if(ioctl(outp, MTIOCTOP, (char *)&op) < 0) {
 111:                     perror("Write EOF");
 112:                     exit(6);
 113:                 }
 114:             }
 115:             filen++;
 116:             count = 0;
 117:             lcount = 0;
 118:             tsize += size;
 119:             size = 0;
 120:             if (nfile && filen > nfile)
 121:                 break;
 122:             ln = n;
 123:         }
 124:     }
 125:     if (copy)
 126:         (void) close(outp);
 127:     printf("total length: %ld bytes\n", tsize);
 128: }
 129: 
 130: RUBOUT()
 131: {
 132:     if (count > lcount)
 133:         --count;
 134:     if (count)
 135:         if (count > lcount)
 136:             printf(msg1, filen, lcount, count, ln);
 137:         else
 138:             printf(msg2, filen, lcount, ln);
 139:     printf("rubout at file %d: record %ld\n", filen, count);
 140:     printf("total length: %ld bytes\n", tsize+size);
 141:     exit(1);
 142: }

Defined functions

RUBOUT defined in line 130; used 2 times
main defined in line 38; never used

Defined variables

buff defined in line 26; used 2 times
copy defined in line 34; used 5 times
copyright defined in line 8; never used
count defined in line 28; used 14 times
filen defined in line 27; used 11 times
inf defined in line 33; used 3 times
lcount defined in line 28; used 13 times
ln defined in line 32; used 14 times
msg1 defined in line 35; used 3 times
msg2 defined in line 36; used 3 times
nfile defined in line 30; used 2 times
  • in line 120(2)
outf defined in line 33; used 3 times
sccsid defined in line 12; never used
size defined in line 31; used 5 times
tsize defined in line 31; used 3 times

Defined macros

SIZE defined in line 24; used 2 times
Last modified: 1996-06-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3191
Valid CSS Valid XHTML 1.0 Strict