delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/01/10/16:13:17

From: scottk AT utig DOT ig DOT utexas DOT edu (Scott Kempf)
Subject: patch for open(), fixes tar overwrite bug
10 Jan 1997 16:13:17 -0800 :
Sender: daemon AT cygnus DOT com
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <199701101642.KAA29672.cygnus.gnu-win32@utig.ig.utexas.edu>
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT 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 AT cygnus DOT com" with one line of text: "help".

- Raw text -


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