[IOStreams] patch for "seek" bug in file descriptor device

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

Frank Birbacher wrote:
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:
This looks similar to: http://svn.boost.org/trac/boost/ticket/856 If so, perhaps you can attach you patch to this bug. Is the second part of your patch related to the following bug entry? http://svn.boost.org/trac/boost/ticket/586 The bigger concern is that nobody seems to be doing any maintenance work on iostreams... (at least it seems that way to me).

Hi! eg schrieb:
This looks similar to: http://svn.boost.org/trac/boost/ticket/856
If so, perhaps you can attach you patch to this bug.
Is the second part of your patch related to the following bug entry? http://svn.boost.org/trac/boost/ticket/586
You are right. That are exactly the bugs I'm solving.
The bigger concern is that nobody seems to be doing any maintenance work on iostreams... (at least it seems that way to me).
Ok, see here http://svn.boost.org/trac/boost/log/sandbox-branches/birbacher/fix_iostreams... :D Frank

Frank Birbacher wrote:
Ok, see here http://svn.boost.org/trac/boost/log/sandbox-branches/birbacher/fix_iostreams...
Frank, if you are going to be the maintainer, would you be so kind as to update the .../libs/maintainers.txt file :-) -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - grafikrobot/yahoo

Hi! Rene Rivera schrieb:
Frank, if you are going to be the maintainer, would you be so kind as to update the .../libs/maintainers.txt file :-)
I'm not the maintainer. This is why the changes are done in a sandbox branch. Frank

Frank Birbacher wrote:
Hi!
eg schrieb:
The bigger concern is that nobody seems to be doing any maintenance work on iostreams... (at least it seems that way to me).
Ok, see here http://svn.boost.org/trac/boost/log/sandbox-branches/birbacher/fix_iostreams...
Great news! Thanks. Ed
participants (3)
-
eg
-
Frank Birbacher
-
Rene Rivera