Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62935 - trunk/libs/iostreams/src
From: steven_at_[hidden]
Date: 2010-06-14 12:09:47


Author: steven_watanabe
Date: 2010-06-14 12:09:47 EDT (Mon, 14 Jun 2010)
New Revision: 62935
URL: http://svn.boost.org/trac/boost/changeset/62935

Log:
Open files in append mode on Windows instead of seeking to the end at every write when std::ios_base::app is passed. Fixes #3323.
Text files modified:
   trunk/libs/iostreams/src/file_descriptor.cpp | 22 ++++++++--------------
   1 files changed, 8 insertions(+), 14 deletions(-)

Modified: trunk/libs/iostreams/src/file_descriptor.cpp
==============================================================================
--- trunk/libs/iostreams/src/file_descriptor.cpp (original)
+++ trunk/libs/iostreams/src/file_descriptor.cpp 2010-06-14 12:09:47 EDT (Mon, 14 Jun 2010)
@@ -62,8 +62,7 @@
     std::streampos seek(stream_offset off, BOOST_IOS::seekdir way);
     static file_handle invalid_handle();
     enum flags {
- close_on_exit = 1,
- append = 4
+ close_on_exit = 1
     };
     file_handle handle_;
     int flags_;
@@ -125,12 +124,16 @@
                  ==
               (BOOST_IOS::app | BOOST_IOS::trunc) )
             boost::throw_exception(BOOST_IOSTREAMS_FAILURE("bad open mode"));
- dwDesiredAccess = GENERIC_WRITE;
- dwCreationDisposition = OPEN_ALWAYS;
         if (mode & BOOST_IOS::app) {
             dwCreationDisposition = OPEN_ALWAYS;
- flags_ |= append;
+ dwDesiredAccess =
+ FILE_APPEND_DATA |
+ FILE_WRITE_ATTRIBUTES |
+ FILE_WRITE_EA |
+ STANDARD_RIGHTS_WRITE |
+ SYNCHRONIZE;
         } else {
+ dwDesiredAccess = GENERIC_WRITE;
             dwCreationDisposition = CREATE_ALWAYS;
         }
     } else {
@@ -252,15 +255,6 @@
 std::streamsize file_descriptor_impl::write(const char* s, std::streamsize n)
 {
 #ifdef BOOST_IOSTREAMS_WINDOWS
- if (flags_ & append) {
- DWORD const dwResult =
- ::SetFilePointer(handle_, 0, NULL, FILE_END);
- if ( dwResult == INVALID_SET_FILE_POINTER &&
- ::GetLastError() != NO_ERROR )
- {
- throw_system_failure("failed seeking within file");
- }
- }
     DWORD ignore;
     if (!::WriteFile(handle_, s, n, &ignore, NULL))
         throw_system_failure("failed writing");


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk