[GHC] #679: using ReadWriteMode in Windows corrupts files

GHC trac at galois.com
Wed Feb 22 11:36:22 EST 2006


#679: using ReadWriteMode in Windows corrupts files
-------------------------------+--------------------------------------------
  Reporter:  aljee at hyper.cx    |          Owner:  simonmar
      Type:  bug               |         Status:  new     
  Priority:  normal            |      Milestone:          
 Component:  libraries/base    |        Version:  6.4.1   
  Severity:  normal            |     Resolution:          
  Keywords:                    |             Os:  Windows 
Difficulty:  Moderate (1 day)  |   Architecture:  Unknown 
-------------------------------+--------------------------------------------
Changes (by simonmar):

  * difficulty:  Unknown => Moderate (1 day)
  * milestone:  6.4.2 =>

Comment:

 Looking at the code, I see the problem.  Seeking backwards to flush the
 read buffer doesn't work on text files in Windows, at least not without
 recording the file position before reading the buffer.  The translation
 isn't invertible; we can't fix this by counting newlines in the buffer.

 I'm going to punt on this for 6.4.2.  Workarounds are to use NoBuffering,
 or open the file in binary mode.  A quick fix would be to count newlines
 in the buffer, but that's not completely correct since the newline
 translation isn't invertible.  Strictly speaking we have to call lseek to
 get the current offset before reading a buffer, and cache this value for
 later flushing.

-- 
Ticket URL: <http://cvs.haskell.org/trac/ghc/ticket/679>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list