With newlib as the libc, the following program would print out the same filename twice:
#include "support/platform_support.h" #include <iostream> int main() { std::string temp1 = get_temp_file_name(); std::string temp2 = get_temp_file_name(); std::cout << temp1 << " " << temp2 << std::endl; }
This breaks a few of the tests similar to input.output/file.streams/fstreams/filebuf.assign/member_swap.pass.cpp which expect the returned filenames to be different.
This patch fixes that bug by creating a TempFileName class which, on construction, is guaranteed to have a unique name.
Please double check the Windows side of the TempFileName class with extra scrutiny. I have neither tested, nor built this on Windows (and I don't have a machine to try it out on either).
It's actually a TempFile, not a TempFileName, since you leave the fd open. I think what you actually wanted was to mkstemp(), stash the name and then close the fd (before leaving the constructor).