Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-03-23 07:07:11


Russell Hind wrote:

> Vladimir Prus wrote:
>>
>> Sure, that's the complexity in creating temporary file. On Linux, you can
>>
>> open(..., O_EXCL....)
>>
>> but then how do you get ifstream out of file descriptor. Surely, there's
>> <ext/stdio_filebuf.h> in g++ 3.2+, but for other compilers one has to
>> find other solutions. I indend to try, but not now.
>>
>
> Would it be so bad to use the platform independent way to create the
> file, and if that suceeeds, close it and then re-open it using the
> ofstream?

Between closing the file and reopening it, somebody can delete the file and
create another one. So your original "does not exist" check is lost in
vain. More details here:

   http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/avoid-race.html#TEMPORARY-FILES

- Volodya


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net