view_growbuf_read_until() suggestion
Roland Illig
roland.illig at gmx.de
Fri Aug 5 16:53:42 UTC 2005
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.
I have run the two appended files on NetBSD, Linux, Solaris, IRIX and
AIX, and all systems have a "greedy" fread(). But this is not mandated
by the standard.
$ make reader writer
$ ./writer | ./reader
25
I would not be surprised if the output were
$ make reader writer
$ ./writer | ./reader
7
7
7
4
Nevertheless I will fix this "bug".
Roland
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reader.c
Type: text/x-csrc
Size: 207 bytes
Desc: not available
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20050805/fa158d13/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: writer.c
Type: text/x-csrc
Size: 233 bytes
Desc: not available
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20050805/fa158d13/attachment-0001.c>
More information about the mc-devel
mailing list