What if I need two temp files without creating them? Or two threads decide to get a temp filename simultaneously?
Where is your logic? Did you not realize that the tempfile name has to be checked for existance before creating it?
BTW the GUID approach is appropiate in all cases, but still the check needs to be made to be absolutely sure.
I agree and would like to add that at the point of generating a random filename, "checking" for existance and rely to that result for the next steps is in my opinion already too late.
I am unsure but think CreateFile() is Windows Api specific so I do not know how to crossplatform... maybe with a TStream as replacement to work with?
My own app uses Windows Api to create me a filehandle what I can use (it loops itself if filename is given and expect as input an existing filepath), multithreaded.