From: scottk@utig.ig.utexas.edu (Scott Kempf)
Subject: patch for open(), fixes tar overwrite bug
10 Jan 1997 16:13:17 -0800
Sender: daemon@cygnus.com
Approved: cygnus.gnu-win32@cygnus.com
Distribution: cygnus
Message-ID: <199701101642.KAA29672.cygnus.gnu-win32@utig.ig.utexas.edu>
Original-To: gnu-win32@cygnus.com
Original-Sender: owner-gnu-win32@cygnus.com

It appears that all postings over xmas were lost.
Since open reported in "gdbm 1.7.3 port complete"
as a problem, I'm reposting all my patches.




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;
      }
  
-
For help on using this list, send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".
