openBinaryTempFile

Phil Ruffwind rf at rufflewind.com
Sat Feb 21 07:38:00 UTC 2015


> If openBinaryTempFile is used in this way a few times in a row, it returns
> the same file name every time.

A quick inspection of the [source code][1] reveals that it uses the process ID
(PID) to generate the initial filename of the temporary file.  If the file
already exists, the number is incremented until a new file is created.  So the
current implementation does in fact have this predictable behavior.

I don't *think* this is insecure (but don't quote me on that), since `O_EXCL`
is used to create the file, but it may be somewhat inefficient if there are a
many files being created by one process or if processes with similar IDs
create temporary files with this method.

[1]: http://hackage.haskell.org/package/base-4.7.0.2/docs/src/System-IO.html#line-467


More information about the Libraries mailing list