[Issue 13996] Function for returning a temporary file with a randomly generated name where the name can be accessed

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Feb 3 16:21:05 PST 2015


https://issues.dlang.org/show_bug.cgi?id=13996

--- Comment #2 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
(In reply to Martin Nowak from comment #1)
> You forgot suffix argument :).

What suffix? As suggested, it takes an optional prefix and randomly generates
the rest. You mean that it should take an extension? Or do you think that it
should take a suffix rather than a prefix? I suppose that if it takes a suffix
rather than a prefix, the extension could just be part of the suffix.

> It's missing for ages, we just needed it for dub
> https://github.com/D-Programming-Language/dub/pull/497#issuecomment-72763326.
> 
> The python implementation takes a reasonable approach, generate random names
> and try to exclusively open the file.
> 
> https://github.com/python/cpython/blob/
> 1196330dedbe741f8a0c418abcd2956fad29837f/Lib/tempfile.py#L191
> 
> The new function could be called namedTempFile. It's still useful to have a
> tempFile function that directly unlink the file.

I have a working implementation for Linux. The problem is that I can't figure
out how to get _wsopen or any of its relatives to work on Windows. The linker
fails to find them, even when I verify that they're in snn.lib (or whatever the
name of the library is with the stdio stuff in it that comes with dmc). So, I'm
not quite sure what to do. I could easily create a PR, but it's kind of
pointless if it doesn't work on Windows.

As for keeping tmpfile, I suppose that we could - to avoid forcing anyone to
change their code if nothing else - but in my experience, the function is
utterly useless. And replacing it with tempFile would be trivial. instead of

auto file

--


More information about the Digitalmars-d-bugs mailing list