>On Wed, Nov 10, 2010 at 3:58 AM, Tom Christiansen <tchr...@perl.com> wrote: >> It is neither necessary nor sufficient to check the return value >> from print to detect an error in print.
>I agree it's not sufficient, but I don't agree it's not necessary. >Just imagine a program waiting for a reply to a question that never >reached the other side of a pipe. IMO not checking print's return >value can cause worse bugs than not checking close because it's much >more likely to affect the flow of the program. You can't trust print(). Technically, you can't trust write(2), either. That's why you need to call fsync(2). To my knowledge, only vi(1) does. >> Certainly it can!! >Enlighten me :-) The most common read(2) failure is EIO, but you can also get EINTR and EAGAIN. NFS failures may or may not fall under EIO; I believe those may give ETIMEDOUT or ECONNRESET, which can also happen on a regular socket. And of course you can always get ENOBUFS, which is a real bummer. So any of those will stickly set the ferror flag on the buffer, which will show up in the close. Even close(2) itself can fail, including through EINTR or once again, through EIO form a previously uncommitted write(2) having its own trouble. I have seen many and perhaps all of those. ALWAYS TEST ANYTHING THAT CAN RETURN AN ERROR. ALWAYS!!! --tom