[Haskell-cafe] Exclusive mode in openFile

Gracjan Polak gracjanpolak at gmail.com
Wed Jun 29 12:59:02 CEST 2011

Max Bolingbroke <batterseapower <at> hotmail.com> writes:

Thanks for the link. I tried to use it:

Prelude System.Posix.IO> fd1 <- openFd "xxx.tmp" WriteOnly (Just 0666)
Loading package unix- ... linking ... done.
Prelude System.Posix.IO> fd2 <- openFd "xxx.tmp" WriteOnly (Just 0666)
Prelude System.Posix.IO> print (fd1,fd2)
Prelude System.Posix.IO> h1 <- fdToHandle fd1
Prelude System.Posix.IO> h2 <- fdToHandle fd2
*** Exception: openFile: resource busy (file is locked)

So I can open file twice. So far so good. Then I convert Fds to Handles and
second conversion fails.

I'm looking for file locking code in GHC.IO.* modules, but cannot find any.

How do I convince fdToHandle to create an independent handle to non-locked file?


More information about the Haskell-Cafe mailing list