Missing ftruncate

Simon Marlow simonmar at microsoft.com
Thu Jan 6 09:58:49 EST 2005

Yes, I had in mind having openTempFile and withTempFile built on top of
it.  You're right that withTempFile doesn't currently create the file
and hence is unsafe - it should create the file, and it should pass a
Handle to the IO action.


On 06 January 2005 13:49, Krasimir Angelov wrote:

> withTempFile isn't safe. It will generate the same
> name if it is executed two time consequently and the
> temporary file isn't created in the mean time. I also
> thought about something like withTempFile but there
> are some use cases in which it is useless.
> openTempFile is simpler and on top of it withTempFile
> can be implemented safely.
> --- Simon Marlow <simonmar at microsoft.com> wrote:
>> On 04 January 2005 17:51, Krasimir Angelov wrote:
>>>  I also would like to have some functions for creation
>>> of temporary files. My proposal is:
>>> openTempFile :: FilePath
>>>              -> String
>>>              -> IO (FilePath, Handle)
>>> openBinaryTempFile :: ...
>>> The first argument is the directory where to create
>>> the file and the second argument is the file name
>>> template. The template is something like "foo.bar"
>>> with this template the name of the created file will
>>> be fooXXX.bar where XXX is some random number. The
>>> function should create immediatelly the file in order
>>> to prevent other processes to create a file with the
>>> same name. The returned path is the complete path to
>>> the created file and the handle is the handle to the
>>> created file.
>> See withTempFile in Distribution.Simple.Utils; in
>> many cases it is
>> better to use the 'with'-style to eliminate the
>> possibility of
>> forgetting to remove the temporary file later.
>> Sometimes the 'with'
>> style isn't appropriate, but in those cases you
>> should keep a list of
>> temporary files and remove them with a top-level
>> exception handler (like
>> GHC does).
>> Cheers,
>> 	Simon
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - 250MB free storage. Do more. Manage less.
> http://info.mail.yahoo.com/mail_250

More information about the Libraries mailing list