fread with a pipe and a skip

Olaf Till olaf.till at uni-jena.de
Thu Mar 12 03:34:13 CDT 2009


On Wed, Mar 11, 2009 at 08:12:19PM -0400, John W. Eaton wrote:
> On 11-Mar-2009, spasmous wrote:
> 
> | I have a code snippet below that reproduces what may be a bug. Basically,
> | when freading from a pipe and using the skip argument, the pipe is not fully
> | read in. Results for running the code on my system (3.03) are:
> | 
> | octave:7> mytest
> | done = 1111 2222 3333 4444 5555 6666
> | done = 111122223333444455556666
> | done = 1111 2222 3333 4444 5555 6666
> | done = 1111
> | octave:8>
> 
> Skipping is currently implemented by calling seek.  That's not
> reliable when reading from a pipe.  Should we fix it by reading
> instead of seeking?  That could work for reading, but what about
> writing?  I don't think we want to actually write anything when
> skipping, so I don't see a solution to handling skip for writing  

Maybe I do not understand what skipping in writing should do, but
isn't skipping in writing to a pipe similar to skipping while writing
into a new file or over the end of an existing file? In all these
cases it is not clear what to write into the "gaps". What is the
expected behavior in skipping while writing to a new file? Shouldn't
skipping while writing to a pipe behave equally?

> Or
> should we just print a warning (or fail with an error) if skip is not
> zero when the stream is a pipe (whether open for reading or writing)?

Allowing skipping at least when _reading_ from a pipe could probably
save some memory space since unneeded data is discarded at once after
beeing read ...

BTW I can not see an effect of skipping in writing to a file in 3.0.2:

octave:1> a = "1111111111111111";
octave:2> length (a)
ans =  16
octave:3> b = "2222222222222222";
octave:4> length (b)
ans =  16
octave:5> fid = fopen ("testfile", "w");
octave:6> fwrite (fid, a);
octave:7> fclose (fid);
octave:8> system ("cat testfile");
1111111111111111octave:9> 
octave:9> fid = fopen ("testfile", "w")
fid =  3
octave:10> fwrite (fid, b, "3*char", 1);
octave:11> fclose (fid);
octave:12> system ("cat testfile");
2222222222222222octave:13> 


More information about the Bug-octave mailing list