# HG changeset patch # User Lachlan Andrew # Date 1460459150 -36000 # Node ID fe0a6de805e4f09160ded882f0ec5c49500c792c # Parent f458313c0de47024544a91e2f70dcacdf89e0b82 textscan: Leave file read position correct at exit (bug #47671) * oct-stream.cc (delimited_stream::refresh_buf): Track movement of data within the buffer. * file-io.cc (Ftextscan): New BIST test. diff -r f458313c0de4 -r fe0a6de805e4 libinterp/corefcn/file-io.cc --- a/libinterp/corefcn/file-io.cc Wed Apr 13 14:50:32 2016 -0700 +++ b/libinterp/corefcn/file-io.cc Tue Apr 12 21:05:50 2016 +1000 @@ -1872,6 +1872,18 @@ %! assert (A{4}, [4 ; 8], 1e-6); %! assert (E); +## Test leaving the file at the correct position on exit +%!test +%! f = tempname (); +%! fid = fopen (f, "w+"); +%! fprintf (fid, "1,2\n3,4\n"); +%! fseek (fid, 0, "bof"); +%! A = textscan (fid, "%s %f", 2, "Delimiter", ","); +%! E = ftell (fid); +%! fclose (fid); +%! unlink (f); +%! assert (E, 8); + ## Tests reading with empty format; empty fields & incomplete lower row %!test %! f = tempname (); diff -r f458313c0de4 -r fe0a6de805e4 libinterp/corefcn/oct-stream.cc --- a/libinterp/corefcn/oct-stream.cc Wed Apr 13 14:50:32 2016 -0700 +++ b/libinterp/corefcn/oct-stream.cc Tue Apr 12 21:05:50 2016 +1000 @@ -1428,7 +1428,10 @@ octave_quit (); // allow ctrl-C if (old_remaining > 0) - memmove (buf, idx, old_remaining); + { + buf_in_file += (idx - buf); + memmove (buf, idx, old_remaining); + } progress_marker -= idx - buf; // where original idx would have been idx = buf;