[comp.sources.d] Bug in compress 4.0

stu@gtisqr.uucp (Stu Donaldson) (09/15/90)

Here is a patch to fix a bug I found in compress (zcat).  

The problem would occur when trying to zcat a file that was the maximum
length filename, and didn't have the .Z stuck on the end.  These files
would often be created by transferring compressed files from BSD systems
to a System V system which would truncate the name to 14 chars.

When processing the filenames, compress leaves the variable ofname with
the standard output filename format of a file. 

Thus, when doing a 'zcat abc.Z', the variable ofname would be 'abc'. 

This is just fine unless the input filename is 'abcdefghijklmn' 
(the '.Z' truncated off is truncated on System V). 
Now ofname="abcdefghijklmn" which is also the input filename. 

If compress encounters an error during it's operation, or an interrupt, 
it will try to unlink(ofname) which in the case described above, will 
remove the file you were trying to look at.

My solution was to not unlink the output file on errors if doing a zcat.

================================================================
*** ../y/compress.c	Fri Sep 14 09:41:40 1990
--- compress.c	Fri Sep 14 09:23:29 1990
***************
*** 1264,1270 ****
  writeerr()
  {
      perror ( ofname );
!     unlink ( ofname );
      exit ( 1 );
  }
  
--- 1264,1270 ----
  writeerr()
  {
      perror ( ofname );
!     if (zcat_flg == 0) unlink ( ofname );
      exit ( 1 );
  }
  
***************
*** 1333,1339 ****
  
  onintr ( )
  {
!     unlink ( ofname );
      exit ( 1 );
  }
  
--- 1333,1339 ----
  
  onintr ( )
  {
!     if (zcat_flg == 0) unlink ( ofname );
      exit ( 1 );
  }
  
***************
*** 1341,1347 ****
  {
      if ( do_decomp == 1 ) 
      	fprintf ( stderr, "uncompress: corrupt input\n" );
!     unlink ( ofname );
      exit ( 1 );
  }
  
--- 1341,1347 ----
  {
      if ( do_decomp == 1 ) 
      	fprintf ( stderr, "uncompress: corrupt input\n" );
!     if (zcat_flg == 0) unlink ( ofname );
      exit ( 1 );
  }
--
Stu Donaldson          UUCP: {smart-host}!gtisqr!stu
Maverick Microsystems  ARPA: gtisqr!stu@yang.cpac.washington.edu
Mukilteo, Washington   Bell: (206) 743-6659