
Hi! I have had a hard time trying to figure out why my windows port of a file transfer program would not write anything to its files. I'm using boost svn, msvc 8 express, platform sdk from msvc 2003, and windows xp (SP2). I discovered that the file_descriptor device of the IOStreams library does not check for SetFilePointer failure as Microsoft recommands. This led to always throwing bad_seek. But the write function on the std::ostream& does neither return with the failbit set nor does it propagate the exception. Anyway the attached patch on the boost svn should fix this problem. I added a second check for failure as the MSDN ( http://msdn.microsoft.com/library/en-us/fileio/fs/setfilepointer.asp , see "Return Value") suggests. It works for me. Here is where I started: $LC_ALL=C svn info Path: . URL: http://svn.boost.org/svn/boost/trunk Repository Root: http://svn.boost.org/svn/boost Repository UUID: b8fc166d-592f-0410-95f2-cb63ce0dd405 Revision: 38755 Node Kind: directory Schedule: normal Last Changed Author: grafik Last Changed Rev: 38755 Last Changed Date: 2007-08-18 19:11:07 +0200 (Sat, 18 Aug 2007) $LC_ALL=C svn st ? bin.v2 ? stage ? libs/mpi/doc/mpi_autodoc.xml ? libs/intrusive/doc/autodoc.xml ? libs/logic/doc/reference.xml ? libs/program_options/doc/autodoc.xml ? libs/xpressive/doc/autodoc.xml ? libs/interprocess/doc/autodoc.xml ? libs/function/doc/html ? libs/algorithm/string/doc/autodoc.xml M libs/iostreams/src/file_descriptor.cpp "svn diff" in attached file. Frank Index: libs/iostreams/src/file_descriptor.cpp =================================================================== --- libs/iostreams/src/file_descriptor.cpp (revision 38755) +++ libs/iostreams/src/file_descriptor.cpp (working copy) @@ -159,8 +159,10 @@ #ifdef BOOST_IOSTREAMS_WINDOWS if (pimpl_->flags_ & impl::has_handle) { if (pimpl_->flags_ & impl::append) { - ::SetFilePointer(pimpl_->handle_, 0, NULL, FILE_END); - if (::GetLastError() != NO_ERROR) + DWORD const dwResult = + ::SetFilePointer(pimpl_->handle_, 0, NULL, FILE_END); + if (dwResult == INVALID_SET_FILE_POINTER + && ::GetLastError() != NO_ERROR) throw detail::bad_seek(); } DWORD ignore; @@ -192,10 +194,12 @@ way == BOOST_IOS::cur ? FILE_CURRENT : FILE_END ); - if (::GetLastError() != NO_ERROR) { + if (dwResultLow == INVALID_SET_FILE_POINTER + && ::GetLastError() != NO_ERROR) { throw detail::bad_seek(); } else { - return offset_to_position((lDistanceToMoveHigh << 32) + dwResultLow); + return offset_to_position( + (stream_offset(lDistanceToMoveHigh) << 32) + dwResultLow); } } #endif // #ifdef BOOST_IOSTREAMS_WINDOWS