boost::filesystem - no create_file or create_tmp_file?
Hi, I'm using boost-1.32 and I didn't find a function which creates an empty file or an empty temporary file?! thx, Oliver -- "Happy ProMail" bis 24. M�rz: http://www.gmx.net/de/go/promail Zum 6. Geburtstag gibt's GMX ProMail jetzt 66 Tage kostenlos!
Oliver Kowalke wrote:
Hi, I'm using boost-1.32 and I didn't find a function which creates an empty file or an empty temporary file?!
Empty file is simple: ofstream ofs("name of file"); Temporary file is harder, and it's not yet supported in boost.filesystem. - Volodya
Vladimir Prus wrote:
Empty file is simple:
ofstream ofs("name of file");
But it would be helpful if boost would add a function that would fail if the file already exists. The current STL doesn't support this so you have to fall back to platform API (in Win32, CreateFile has a flag to do this). This would be a very useful feature IMHO. Cheers Russell
Russell Hind wrote:
Vladimir Prus wrote:
Empty file is simple:
ofstream ofs("name of file");
But it would be helpful if boost would add a function that would fail if the file already exists. The current STL doesn't support this so you have to fall back to platform API (in Win32, CreateFile has a flag to do this).
This would be a very useful feature IMHO.
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
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
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? Cheers Russell
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
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.htm... - Volodya
Vladimir Prus wrote:
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:
And also if you want to open it for exclusive acces, that could fail after you close it. Cheers Russell
participants (3)
-
Oliver Kowalke
-
Russell Hind
-
Vladimir Prus