<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&#39;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">&lt;<a href="mailto:holger@freyther.de" target="_blank">holger@freyther.de</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
&gt; On 23 Sep 2016, at 19:22, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi Holger,<br>
&gt;<br>
<br>
Hey!<br>
<br>
<br>
<br>
<br>
&gt; And as the comment says:<br>
&gt;<br>
&gt;         /* Line buffering in fread can&#39;t be relied upon, at least on Mac OS X<br>
&gt;          * and mingw win32.  So do it the hard way.<br>
&gt;          */<br>
<span class="">&gt;         bytesRead = 0;<br>
&gt;         do {<br>
&gt;             clearerr(file);<br>
&gt;             if (fread(dst, 1, 1, file) == 1) {<br>
&gt;                 bytesRead += 1;<br>
<br>
</span>                        bytesRead &gt; 0 now<br>
<span class=""><br>
&gt;                 if (dst[bytesRead-1] == &#39;\n&#39;<br>
&gt;                  || dst[bytesRead-1] == &#39;\r&#39;)<br>
&gt;                     break;<br>
&gt;             }<br>
&gt;         }<br>
&gt;         while (bytesRead &lt;= 0 &amp;&amp; ferror(file) &amp;&amp; errno == EINTR);<br>
<br>
</span>                        ^^^ false &amp;&amp; ? &amp;&amp; ?<br>
<br>
<br>
&gt;<br>
&gt; That seems like a good idea.  So you&#39;re proposing<br>
&gt;<br>
&gt;             fgets(dst,1,file)<br>
&gt;<br>
&gt; 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&#39;t need/want the NUL termination here. (and I don&#39;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 &lt;= 0 &amp;&amp; ferror(file) &amp;&amp; errno == EINTR)<br>
<br>
</span>to:<br>
<br>
        while (bytesRead &lt;= count &amp;&amp; ferror(file) &amp;&amp; errno == EINTR)<br>
<br>
<br>
cheers<br>
<span class="HOEnZb"><font color="#888888">        holger</font></span></blockquote></div><br></div>