> On Sep 17, 2017, at 4:53 AM, Marc Espie <es...@nerim.net> wrote:
> 
> On Sat, Sep 16, 2017 at 10:25:19PM -0500, Scott Cheloha wrote:
>> Hi,
>> 
>> [...]
>> 
>> --
>> Scott Cheloha
>> 
>> Index: lib/libc/sys/write.2
>> ===================================================================
>> RCS file: /cvs/src/lib/libc/sys/write.2,v
>> retrieving revision 1.39
>> diff -u -p -r1.39 write.2
>> --- lib/libc/sys/write.2     5 Feb 2015 02:33:09 -0000       1.39
>> +++ lib/libc/sys/write.2     17 Sep 2017 03:02:57 -0000
>> @@ -311,7 +311,7 @@ function call appeared in
>> Error checks should explicitly test for \-1.
>> Code such as
>> .Bd -literal -offset indent
>> -while ((nr = write(fd, buf, sizeof(buf))) > 0)
>> +while ((nw = write(fd, buf, sizeof(buf))) > 0)
>> .Ed
>> .Pp
>> is not maximally portable, as some platforms allow for
>> @@ -325,5 +325,5 @@ and
>> may appear as a negative number distinct from \-1.
>> Proper loops should use
>> .Bd -literal -offset indent
>> -while ((nr = write(fd, buf, sizeof(buf))) != -1 && nr != 0)
>> +while ((nw = write(fd, buf, sizeof(buf))) != -1 && nw == sizeof(buf))
>> .Ed
> 
> Well, that's not okay either, because nw == sizeof(buf) will only make
> sense for file-based fds.

Ah, okay.  So my third question was about partial writes.

I left it out because I figured that we could just say explicitly
that the examples did not cover partial writes if need be.

At least, I think that's what you mean when you say that '== sizeof(buf)'
only makes sense for file-based fds.

> I'm for either scraping the example altogether or writing a proper
> one, which would mean embedding any version of safe_write in the
> man page.

Could you point to an example of safe_write in the tree that covers
what you're looking for?  Is it akin to writeall() in signify(1) or
atomicio() for nc(1)?

--
Scott Cheloha

Reply via email to