O_CREAT | O_EXCL with ofstream

Hervé Eychenne rv@eychenne.org
Fri May 28 18:14:00 GMT 2004


 Hi,

I used to use:
 int fd = open("file", O_CREAT | O_EXCL);
 ofstream os(fd);
but ofstream::ofstream(int fd) has also been deprecated (sigh), so
I see no way anymore to atomically ensure that a file was not already
existing when creating a new one.
I've searched everywhere on the Web, and I could only find a
reference of a ios_base::noreplace which does not seem to exist.

So how do I get an ofstream while ensuring atomicity? (O_CREAT | O_EXCL behaviour)
Any clue?

 Herve

-- 
 _
(°=  Hervé Eychenne
//)  Homepage:          http://www.eychenne.org/
v_/_ WallFire project:  http://www.wallfire.org/



More information about the Libstdc++ mailing list