O_CREAT |?O_EXCL with ofstream
Jonathan Wakely
cow@compsoc.man.ac.uk
Fri May 28 18:57:00 GMT 2004
On Fri, May 28, 2004 at 06:07:15PM +0200, Herv? Eychenne wrote:
> 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?
Which compiler version are you using?
Have you looked at the <ext/stdio_filebuf.h> header?
See http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#11
jon
--
"Capitalism is the extraordinary belief that the nastiest of men, for the
nastiest of reasons, will somehow work for the benefit of us all."
- John Maynard Keynes
More information about the Libstdc++
mailing list