[Hackage] #473: Cabal-1.6 does not work on Windows with ghc-6.6.x

Hackage trac at galois.com
Thu Jan 22 12:13:51 EST 2009

#473: Cabal-1.6 does not work on Windows with ghc-6.6.x
  Reporter:  duncan               |        Owner:           
      Type:  defect               |       Status:  new      
  Priority:  normal               |    Milestone:  Cabal-1.6
 Component:  Cabal library        |      Version:  
  Severity:  normal               |     Keywords:           
Difficulty:  very easy (<1 hour)  |   Ghcversion:  6.6.1    
  Platform:  Windows              |  

 The problem is the `writeFileAtomic` function calls the compat version of
 `openNewBinaryFile` and that fails on Windows with ghc-6.6. Specifically
 it is the `fdToHandle` that throws the exception.

 The crux is:
 fd <- withCString filepath $ \ f ->
         c_open f oflags 0o666
 h <- fdToHandle (fromIntegral fd)

 However `fdToHandle` fails with the exception
 fdGetMode: invalid argument

 This is because in ghc-6.6.x, the `fdToHandle` calls `fdGetMode` and
 passes the result to `openFd`:
 fdToHandle :: FD -> IO Handle
 fdToHandle fd = do
    mode <- fdGetMode fd
    let fd_str = "<file descriptor: " ++ show fd ++ ">"
    openFd fd Nothing False{-XXX!-} fd_str mode True{-bin mode-}

 However `fdGetMode` is described thusly:
 fdGetMode fd = do
 #if defined(mingw32_HOST_OS) || defined(__MINGW32__)
     -- XXX: this code is *BROKEN*, _setmode only deals with

 Note that the `openBinaryTempFile` function does not call `fdToHandle`,
 instead it bypasses it and calls `openFd` directly.

 The `openFd` function is exported from `GHC.Handle` so we could use it in

Ticket URL: <http://hackage.haskell.org/trac/hackage/ticket/473>
Hackage <http://haskell.org/cabal/>
Hackage: Cabal and related projects

More information about the cabal-devel mailing list