openTempFile only defined on GHC
simonmarhaskell at gmail.com
Tue Apr 10 06:13:10 EDT 2007
Neil Mitchell wrote:
>> Perhaps as a first step, rather than just omitting them from the
>> export list
>> where they aren't supported, they should be replaced by dummy
>> definitions that
>> emit a helpful error message?
> Like canonicalizeFilePath, which has a dummy implementation
> everywhere? It's frustrating to have a standard base library which
> isn't standard and portable. I realise that the reason that this was
> added was for race-free temporary file creation, but until they are
> available on Hugs, my code will use a race-full implementation
> everywhere, including GHC.
> Could we perhaps have an implementation of this function for all other
> -- Note: openTempFile is not available on Hugs, which sucks
> openTempFileLocal :: FilePath -> String -> IO (FilePath, Handle)
> openTempFileLocal dir template = do
> i <- randomRIO (1000::Int,9999)
> let (file,ext) = splitExtension template
> s = dir </> (file ++ show i) <.> ext
> b <- doesFileExist s
> if b then openTempFileLocal dir template else do
> h <- openFile s ReadWriteMode
> return (s, h)
> That's what I use everywhere.
What does the "local" in openTempFileLocal mean? I'd be perfectly happy to have
non-race-free implementations of openTempFile for certain compilers/platforms as
long as we document it (not that we document openTempFile properly at all at the
moment, which is a bug).
Also note that you can't use </> or <.> here, because filepath is not in base :-)
>> I suspect there are many such examples in the base package, FWIW.
>> nch98 doesn't
>> implement various bits of System.IO.Error, for example. Hugs has a very
>> different version of Control.Concurrent.
> I think these should be made very explicit in the documentation.
> Control.Concurrent is understandable, things like file creation
> methods aren't - a user will be annoyed (and I was) to find that their
> program written according to the documentation doesn't work.
I quite agree. Care to send a patch, or open a ticket?
More information about the Libraries