Subject: patch for open(), fixes tar overwrite bug
From: [email-masked] (Scott Kempf)

10 Jan 1997 16:13:17 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Original-To: [email-masked]
Original-Sender: [email-masked]

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
"[email-masked]" with one line of text: "help".