Boost C++ Libraries: Ticket #3884: boost fstream 'enforces' in AND out mode. It should be be possible to open a read-only file using fstream. https://svn.boost.org/trac10/ticket/3884 <p> boost fstream 'enforces' in AND out mode by adding both in and out flags to the user specified file open mode. </p> <p> Check boost\filesystem\fstream.hpp line 479, it does: </p> <blockquote> <p> mode | std::ios_base::in | std::ios_base::out </p> </blockquote> <p> This makes it impossible to use fstream object to open a file for only reading or writing. This is especially troublesome when trying to open a read-only file as open call will fail with access denied error. </p> <p> Fix: fstream should not modify 'mode' value and use the user specified value as is. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3884 Trac 1.4.3 Steven Watanabe Mon, 01 Feb 2010 21:53:01 GMT <link>https://svn.boost.org/trac10/ticket/3884#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3884#comment:1</guid> <description> <p> If you know at compile time whether you are only going to read/write you should use ifstream or ofstream instead. </p> </description> <category>Ticket</category> </item> <item> <author>Sachin Garg <schngrg@…></author> <pubDate>Tue, 02 Feb 2010 17:54:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3884#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3884#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3884#comment:1" title="Comment 1">steven_watanabe</a>: </p> <blockquote class="citation"> <p> If you know at compile time whether you are only going to read/write you should use ifstream or ofstream instead. </p> </blockquote> <p> File opening mode is decided at run-time and it workes fine when working with std::fstream objects (at least with Microsoft's implementation of it, didn't try on gcc). </p> <p> We also need a common base class to hold the open file stream objects (ifstream does not inherit from fstream, it's the other way round). If we use ifstream object when opening files only for reading, we won't be able to pass the object around with other fstream objects. </p> </description> <category>Ticket</category> </item> <item> <author>Sachin Garg <schngrg@…></author> <pubDate>Tue, 02 Feb 2010 18:00:04 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/3884#comment:3 https://svn.boost.org/trac10/ticket/3884#comment:3 <ul> <li><strong>cc</strong> <span class="trac-author">schngrg@…</span> added </li> </ul> <p> Also, boost::fstream is implemented as a wrapper over std::fstream (it uses a std::fstream object internally), which means that if any changes to 'mode' value are indeed needed, then the std::fstream::open() can do that internally. I am unable to see the reason for boost's wrapper to change its value before passing it to std::fstream. </p> <p> (We are using boost's fstream because it lets us directly use wpath filenames which is is huge convenience compared to using std::fstream's char*) </p> Ticket Beman Dawes Wed, 10 Feb 2010 17:21:45 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3884#comment:4 https://svn.boost.org/trac10/ticket/3884#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/59622" title="Fix #3884">[59622]</a>) Fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3884" title="#3884: Bugs: boost fstream 'enforces' in AND out mode. It should be be possible to ... (closed: fixed)">#3884</a> </p> Ticket Beman Dawes Wed, 10 Feb 2010 17:22:49 GMT <link>https://svn.boost.org/trac10/ticket/3884#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3884#comment:5</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/59623" title="Fix #3884">[59623]</a>) Fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3884" title="#3884: Bugs: boost fstream 'enforces' in AND out mode. It should be be possible to ... (closed: fixed)">#3884</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>