<div dir="ltr"><div>So if I understand it, isStdioStream means one of stdin stdout stderr?<br></div>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.<br></div><div class="gmail_extra"><br><div class="gmail_quote">2016-09-23 21:08 GMT+02:00 Holger Freyther <span dir="ltr"><<a href="mailto:holger@freyther.de" target="_blank">holger@freyther.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On 23 Sep 2016, at 19:22, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> wrote:<br>
><br>
> Hi Holger,<br>
><br>
<br>
Hey!<br>
<br>
<br>
<br>
<br>
> And as the comment says:<br>
><br>
> /* Line buffering in fread can't be relied upon, at least on Mac OS X<br>
> * and mingw win32. So do it the hard way.<br>
> */<br>
<span class="">> bytesRead = 0;<br>
> do {<br>
> clearerr(file);<br>
> if (fread(dst, 1, 1, file) == 1) {<br>
> bytesRead += 1;<br>
<br>
</span> bytesRead > 0 now<br>
<span class=""><br>
> if (dst[bytesRead-1] == '\n'<br>
> || dst[bytesRead-1] == '\r')<br>
> break;<br>
> }<br>
> }<br>
> while (bytesRead <= 0 && ferror(file) && errno == EINTR);<br>
<br>
</span> ^^^ false && ? && ?<br>
<br>
<br>
><br>
> That seems like a good idea. So you're proposing<br>
><br>
> fgets(dst,1,file)<br>
><br>
> right? Much nicer. To whoever implements this please test on Windows and Mac OS and Linux.<br>
<br>
<br>
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);<br>
<br>
My new proposal then is to change<br>
<span class=""><br>
while (bytesRead <= 0 && ferror(file) && errno == EINTR)<br>
<br>
</span>to:<br>
<br>
while (bytesRead <= count && ferror(file) && errno == EINTR)<br>
<br>
<br>
cheers<br>
<span class="HOEnZb"><font color="#888888"> holger</font></span></blockquote></div><br></div>