view growbuf read until() suggestion
Pavel Tsekov
ptsekov at gmx.net
Fri Aug 5 21:38:55 UTC 2005
> Hello,
>
> > --- Ursprüngliche Nachricht ---
> > Von: Roland Illig
> > An: MC dev
> > Betreff: Re: view_growbuf_read_until() suggestion
> > Datum: Fri, 05 Aug 2005 18:53:42 +0200
> >
> > Pavel Tsekov wrote:
> > > I forgot to attach the patch in the original message.
> > >
> > > On Fri, 5 Aug 2005, Pavel Tsekov wrote:
> > >
> > >
> > >>Hello Roland,
> > >>
> > >>There is a small "bug" in the new viewer code. When the viewer is used
> > in
> > >>growing buffer mode it incorrectly displays in the status bar ">=
> size"
> > >>even if the data source was exhausted and despite the fact the the
> > >>size of the whole buffer is known. Please, take a look at the attached
> > >>patch for a idea how to fix it. Of course you could find a better way
> to
> > >>solve this since you know the code better.
> >
> > I confirm that the "bug" does not look nice. But your code has a little
> > problem. It _might_ report a too small file size.
> >
> > > nread = fread (p, 1, bytesfree, view->ds_stdio_pipe);
> > > - if (nread == 0) {
> > > + if (nread > 0)
> > > + view->growbuf_lastindex += nread;
> > > + if (nread < bytesfree) {
> >
> > Nothing in the C standard prevents fread from always returning only one
> > element instead of ''bytesfree''. It's just a "quality of
> > implementation" that most system's fread(3) function calls read(2)
> > repeatedly until either EOF is reached or the necessary number of bytes
> > is read.
>
> [...]
> RETURN VALUES
> The functions fread() and fwrite() advance the file position
> indicator
> for the stream by the number of bytes read or written. They return
> the
> number of objects read or written. If an error occurs, or the
> end-of-
> file is reached, the return value is a short object count (or zero).
> [...]
Of course you might still be right in assuming that fread() may return less
bytes than requested. I can imagine that it could happen with a fdopen()-ed
FILE which has a file descriptor in non-blocking mode. This is of coure just
speculation. Of course, calls to feof() and ferror() could be added to
detect the situation where the read didn't fail but still returned less
data.
--
GMX DSL = Maximale Leistung zum minimalen Preis!
2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl
More information about the mc-devel
mailing list