home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / dec / Ultrix-3.0 / rat.c < prev    next >
C/C++ Source or Header  |  1991-11-08  |  879b  |  61 lines

  1. #include <stdio.h>
  2.  
  3. main (argc,argv)
  4.   int argc ;
  5.   char ** argv ;
  6. {
  7.     register int fd, bytes, eof ;
  8.     FILE * ofd ;
  9.     char * buffer ;
  10.     extern char * malloc() ;
  11.  
  12.     buffer = malloc (65535) ;
  13.  
  14.     if ( ( fd = open ("/dev/rmt1600a",0) ) < 0 )
  15.     {
  16.         fprintf (stderr,"%s: can't open tape unit /dev/rmt1600a\n",
  17.             argv[0]) ;
  18.         exit (1) ;
  19.     }
  20.  
  21.     if ( ( ofd = fopen ("./tapedump","w") ) == NULL )
  22.     {
  23.         perror ("./tapedump") ;
  24.         exit (1) ;
  25.     }
  26.  
  27.     for ( eof = 0 ; ; )
  28.     {
  29.         bytes = read (fd,buffer,65535) ;
  30.  
  31.         if ( bytes == 0 )
  32.         {
  33.             if ( eof++ > 0 )
  34.             {
  35.                 printf ("EOT\n") ;
  36.                 break ;
  37.             }
  38.  
  39.             printf ("EOF\n") ;
  40.         }
  41.         else
  42.             if ( bytes < 0 )
  43.             {
  44.                 printf ("I/O-ERROR\n") ;
  45.             }
  46.             else
  47.             {
  48.                 printf ("%d\n",bytes) ;
  49.                 eof = 0 ;
  50.  
  51.                 if ( fwrite (buffer,1,bytes,ofd) != bytes )
  52.                     fprintf (stderr,"write error\n") ;
  53.             }
  54.     }
  55.  
  56.     (void) close (fd) ;
  57.     (void) fclose (ofd) ;
  58.  
  59.     exit (0) ;
  60. }
  61.