Missing ftruncate
Simon Marlow
simonmar at microsoft.com
Wed Jan 5 05:18:29 EST 2005
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
More information about the Libraries
mailing list