开发者

std::fstream will not open current process's file, but open() will?

开发者 https://www.devze.com 2023-01-10 12:34 出处:网络
I am attempting to open the current process\'s executable file for read-write operations (I have additional data attached t开发者_开发问答o the executable), however std::fstream will not open the file

I am attempting to open the current process's executable file for read-write operations (I have additional data attached t开发者_开发问答o 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?


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++".


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消