delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/01/02/11:24:56

From: scottk AT rimu DOT ig DOT utexas DOT edu (Scott Kempf)
Subject: patch for open(), fixes tar overwrite bug
2 Jan 1997 11:24:56 -0800 :
Sender: daemon AT cygnus DOT com
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <199701021632.KAA12004.cygnus.gnu-win32@rimu.ig.utexas.edu>
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

I started looking for this bug with tar's failure to overwrite files.  It
turns out the open() didn't work well for some unusual flag combinations.
The following patch fixes tar (which uses both O_TRUNC and O_APPEND)
and appears to conform to my man pages for open().

				Scott

*** cdksrc/src/winsup/fhandler.cc.orig	Mon Dec 30 17:04:41 1996
--- cdksrc/src/winsup/fhandler.cc	Mon Dec 30 17:18:01 1996
***************
*** 318,333 ****
        access_ = GENERIC_READ | GENERIC_WRITE;
      }
  
!   /* FIXME: O_EXCL handling?  */
! 
!   if (flags & O_CREAT)
!     creation_distribution = CREATE_ALWAYS;
    else
!     creation_distribution = OPEN_EXISTING;
  
    if (flags & O_APPEND) 
      {
-       creation_distribution = OPEN_ALWAYS;
        append_p_ = 1;
      }
  
--- 318,353 ----
        access_ = GENERIC_READ | GENERIC_WRITE;
      }
  
!   if ((flags & O_TRUNC) && ((flags & O_ACCMODE) != O_RDONLY))
!     {
!       if (flags & O_CREAT)
!         {
! 	  creation_distribution = CREATE_ALWAYS;
!         }
!       else
!         {
! 	  creation_distribution = TRUNCATE_EXISTING;
!         }
!     }
    else
!     {
!       if (flags & O_CREAT)
!         {
! 	  creation_distribution = OPEN_ALWAYS;
!         }
!       else
!         {
! 	  creation_distribution = OPEN_EXISTING;
!         }
!     }
! 
!   if ((flags & O_EXCL) && (flags & O_CREAT))
!     {
!       creation_distribution = CREATE_NEW;
!     }
  
    if (flags & O_APPEND) 
      {
        append_p_ = 1;
      }
  
----------------------------------
Scott Kempf (scottk AT ig DOT utexas DOT edu)
Running gnu-win32 beta 17.1
under Windows 95.
-
For help on using this list, send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019