tags:

views:

30

answers:

2

I am attempting to open the current process's executable file for read-write operations (I have additional data attached to the executable), however std::fstream will not open the file in ios::in | ios::out | ios::binary mode, even though open() will (with O_RDWR flag set).

Does anyone know why std::fstream will not open the file, while open() will, and if so, how I can get std::fstream to open the file?

A: 

I'd wonder if, somewhere, under the hood, the std::fstream version is calling open - I would bet so. Have you tried checking errno anyways, or perhaps running strace to see what, if any errors, the system call is returning?

Thanatos
+1  A: 

It most probably has to do with file sharing semantics. See this thread which deals with a similar question - and the answer there is "The concept of file protection, file sharing, file permissions is OS-specific, which is why it is not covered by standard C++".

casablanca
Yeah, I suspected that I might have to write my own I/O class for it that uses open(), read(), write(), etc.. underneath. It doesn't really matter since I need to do caching per-block since it's for a filesystem.
Hach-Que