[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: os.tmpname()
- From: Klaus Ripke <paul-lua@...>
- Date: Wed, 30 Nov 2005 15:01:01 +0100
On Wed, Nov 30, 2005 at 11:04:52AM -0200, Frederico Rodrigues Abraham wrote:
> yea, i saw this function, but i only want the filename so i can pass to
> a library who does the fopen...
> since i'm single-thread, i guess tmpname() will do fine...
no, it's not a matter of multithreading
1.) you use tmpname to get a name so far unused
2.) some other process in the system creates a file by that name
3.) you use fopen and open a file used by someone else
the only safe way is to check the uniqueness of the filename
while creating it using appropriate flags to the actual open call
and try another name if that fails.
fopen does not support such a flag, but the underlying system calls
do on both windows and posix.
a typical cooperative workaround is to use a temp dir
with the name of your application and encode your process
id in the file name.
not foolproof, but good enough for most purposes.