# HG changeset patch # User John W. Eaton # Date 1313422223 14400 # Node ID 18797a4b61740a6e5040f8322f5689f376479e4b # Parent fb69561e5901e6b9d1e6117d8a42eb81d4f4d0e1 undo previous unintended change to oct-stream.cc diff -r fb69561e5901 -r 18797a4b6174 src/oct-stream.cc --- a/src/oct-stream.cc Fri Aug 12 14:05:48 2011 -0400 +++ b/src/oct-stream.cc Mon Aug 15 11:30:23 2011 -0400 @@ -3002,51 +3002,38 @@ { clearerr (); - // Find current position so we can return to it if needed. - long orig_pos = rep->tell (); - // Move to end of file. If successful, find the offset of the end. - - status = rep->seek (0, SEEK_END); + status = rep->seek (offset, origin); if (status == 0) { - long eof_pos = rep->tell (); - - // Attempt to move to desired position; may be outside bounds - // of existing file. - - status = rep->seek (offset, origin); - - if (status == 0) + long save_pos = rep->tell (); + + rep->seek (0, SEEK_END); + + long pos_eof = rep->tell (); + + // I don't think save_pos can be less than zero, but we'll + // check anyway... + + if (save_pos > pos_eof || save_pos < 0) { - // Where are we after moving to desired position? - - long desired_pos = rep->tell (); - - // I don't think desired_pos can be less than zero, but - // we'll check anyway... - - if (desired_pos > eof_pos || desired_pos < 0) - { - // Seek outside bounds of file. Failure should leave - // position unchanged. - - rep->seek (orig_pos, SEEK_SET); - - status = -1; - } - } - else - { - // Seeking to the desired position failed. Move back to - // original position and return failure status. + // Seek outside bounds of file. Failure should leave + // position unchanged. rep->seek (orig_pos, SEEK_SET); status = -1; } + else + { + // Is it possible for this to fail? We are just + // returning to a position after the first successful + // seek. + + rep->seek (save_pos, SEEK_SET); + } } }