Re: write.2: caveats: write(2) returns zero?

2017-09-21 Thread Ingo Schwarze
Hi Raul, Raul Miller wrote on Wed, Sep 20, 2017 at 06:31:03PM -0400: > What are the correct cases where write(2) writes 0 bytes and that is > considered success (as opposed to being one of the documented error > cases)? Most importantly, nbytes == 0. On OpenBSD, we are not aware of any other

Re: write.2: caveats: write(2) returns zero?

2017-09-20 Thread Raul Miller
On Wed, Sep 20, 2017 at 5:52 PM, Marc Espie wrote: > On Wed, Sep 20, 2017 at 09:21:53PM +0200, Ingo Schwarze wrote: >> So, apart from being safer for weird devices on weird implementations, >> POSIX clearly recommends the idiom for symmetry with read(2) and >> for compatibility

Re: write.2: caveats: write(2) returns zero?

2017-09-20 Thread Marc Espie
On Wed, Sep 20, 2017 at 09:21:53PM +0200, Ingo Schwarze wrote: > So, apart from being safer for weird devices on weird implementations, > POSIX clearly recommends the idiom for symmetry with read(2) and > for compatibility with some historic implementations - even though > the importance of these

Re: write.2: caveats: write(2) returns zero?

2017-09-20 Thread Ingo Schwarze
Hi, Todd C. Miller wrote on Mon, Sep 18, 2017 at 09:35:45AM -0600: > On Mon, 18 Sep 2017 16:50:41 +0200, Ingo Schwarze wrote: >> Indeed, the above code is nonsensical. >> It will write the same bytes repeatedly in case of partial writes. > OK millert@ Committed, thanks for checking. > That

Re: write.2: caveats: write(2) returns zero?

2017-09-18 Thread Todd C. Miller
On Mon, 18 Sep 2017 16:50:41 +0200, Ingo Schwarze wrote: > Indeed, the above code is nonsensical. > It will write the same bytes repeatedly in case of partial writes. OK millert@ That does look much better, though I'm not convinced that write(2) will ever return 0 unless nbytes is also 0.

Re: write.2: caveats: write(2) returns zero?

2017-09-18 Thread Marc Espie
On Mon, Sep 18, 2017 at 04:50:41PM +0200, Ingo Schwarze wrote: > Hi Marc, > > Marc Espie wrote on Sun, Sep 17, 2017 at 11:53:39AM +0200: > > On Sat, Sep 16, 2017 at 10:25:19PM -0500, Scott Cheloha wrote: > > >> The second example in the write(2) CAVEATS section is identical to > >> the

Re: write.2: caveats: write(2) returns zero?

2017-09-18 Thread Ingo Schwarze
Hi Marc, Marc Espie wrote on Sun, Sep 17, 2017 at 11:53:39AM +0200: > On Sat, Sep 16, 2017 at 10:25:19PM -0500, Scott Cheloha wrote: >> The second example in the write(2) CAVEATS section is identical to >> the corresponding example in the read(2) page: >> >> while ((nr = write(fd, buf,

Re: write.2: caveats: write(2) returns zero?

2017-09-17 Thread Scott Cheloha
> On Sep 17, 2017, at 4:53 AM, Marc Espie wrote: > > On Sat, Sep 16, 2017 at 10:25:19PM -0500, Scott Cheloha wrote: >> Hi, >> >> [...] >> >> -- >> Scott Cheloha >> >> Index: lib/libc/sys/write.2 >> === >> RCS

Re: write.2: caveats: write(2) returns zero?

2017-09-17 Thread Marc Espie
On Sat, Sep 16, 2017 at 10:25:19PM -0500, Scott Cheloha wrote: > Hi, > > The second example in the write(2) CAVEATS section is identical to > the corresponding example in the read(2) page: > > while ((nr = write(fd, buf, sizeof(buf))) != -1 && nr != 0) > > read(2) returns 0 on EOF, but

write.2: caveats: write(2) returns zero?

2017-09-16 Thread Scott Cheloha
Hi, The second example in the write(2) CAVEATS section is identical to the corresponding example in the read(2) page: while ((nr = write(fd, buf, sizeof(buf))) != -1 && nr != 0) read(2) returns 0 on EOF, but that logic is inapplicable to write(2). I'm not totally sure what the correct