Re: [hackers] [sbase] Rewrite foldline() in fold(1) || FRIGN
On Tue, Mar 17, 2015 at 11:35:33AM +0100, Roberto E. Vargas Caballero wrote:
>
> Hi,
>
> > + for (p = str, col = 0; *p && *p != '\n'; p++) {
> > + if (!UTF8_POINT(*p) && !bflag)
> > + continue;
> > + if (col >= width) {
> > + off = (sflag && spacesect) ? spacesect - str : p - str;
> > + if (fwrite(str, 1, off, stdout) != off)
> > + eprintf("fwrite <stdout>:");
> > + putchar('\n');
> ...
> > + fputs(str, stdout);
>
> It's a bit strange this fwrite, why don't you use putchar there?, and
> why you check the return value of fwrite, but not the return value of
> putcharor fputs?. I usually don't check the return value of write
> functions and at the end of the loop I do a call to ferror.
If fwrite() fails with a short element count, will ferror() always be
on true? I am not sure we can rely on this.
And also if fwrite() fails is it guaranteed that it will continue to
fail on all future calls?
Received on Tue Mar 17 2015 - 11:45:03 CET
This archive was generated by hypermail 2.3.0
: Tue Mar 17 2015 - 11:48:10 CET