[Vm-dev] FilePlugin and reading from stdio

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Fri Sep 23 19:26:41 UTC 2016


So if I understand it, isStdioStream means one of stdin stdout stderr?
It would deserve a comment because it's not that obvious, to me it means
level 3 standard input/output like in man 3 stdio, as opposed to level 2
file descriptors. Not just the pre-opened input/output/error streams.

2016-09-23 21:08 GMT+02:00 Holger Freyther <holger at freyther.de>:

>
>
> > On 23 Sep 2016, at 19:22, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> >
> > Hi Holger,
> >
>
> Hey!
>
>
>
>
> > And as the comment says:
> >
> >         /* Line buffering in fread can't be relied upon, at least on Mac
> OS X
> >          * and mingw win32.  So do it the hard way.
> >          */
> >         bytesRead = 0;
> >         do {
> >             clearerr(file);
> >             if (fread(dst, 1, 1, file) == 1) {
> >                 bytesRead += 1;
>
>                         bytesRead > 0 now
>
> >                 if (dst[bytesRead-1] == '\n'
> >                  || dst[bytesRead-1] == '\r')
> >                     break;
> >             }
> >         }
> >         while (bytesRead <= 0 && ferror(file) && errno == EINTR);
>
>                         ^^^ false && ? && ?
>
>
> >
> > That seems like a good idea.  So you're proposing
> >
> >             fgets(dst,1,file)
> >
> > right?  Much nicer.  To whoever implements this please test on Windows
> and Mac OS and Linux.
>
>
> I had fgets(dst, count, file) in mind but after re-reading the manpage we
> don't need/want the NUL termination here. (and I don't think doing
> something like char buf[count+1]; fgets.; memcpy(dst, buf, size);
>
> My new proposal then is to change
>
>         while (bytesRead <= 0 && ferror(file) && errno == EINTR)
>
> to:
>
>         while (bytesRead <= count && ferror(file) && errno == EINTR)
>
>
> cheers
>         holger
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20160923/1c5fd400/attachment.htm


More information about the Vm-dev mailing list