From: David Abrahams (dave_at_[hidden])
Date: 2004-07-15 13:55:08
Christoph Ludwig <cludwig_at_[hidden]> writes:
> On Thu, Jul 15, 2004 at 10:02:22AM -0700, Robert Ramey wrote:
>> Guillaume Melquiond wrote:
>> >So it may be a good idea to completely remove the function "tmpnam" from
>> >the Serialization library and use a saner replacement instead. This way,
>> >the library tests would compile without any complaint from the linker on
>> I need this functionality to run the tests. What is the best way to go
>> about it?
> The (linux) man page tmpnam(3) recommends to use mkstemp(3)
> instead. (It should be available on most Unix systems since it is
> a POSIX function. I don't know about Windows.)
> However, mkstemp(3) not only generates a unique filename but it also
> opens the corresponding file and returns the file descriptor. You'd
> have to close the file, possibly remove it, and then pass the filename
> to the constructor of your stream which will create and open the file
> again. That sounds like a hack to me and may not be portable.
And I think it undermines the big reason tmpnam is not recommended:
someone can come along and grab the same name and you will overwrite
their file by mistake.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com