Tom Lane <tgl@sss.pgh.pa.us> writes:
> Chris Jones <chris@mt.sri.com> writes:
> > If write didn't return -1, it shouldn't have set errno. A short write
> > count isn't an error condition.
>
> On disk files it certainly is; there's no non-error reason to do that,
> and AFAICS no reason for the application to try again.
Probably true, but on Unix you certainly can't assume that write will
set errno if it does not return -1. On Linux systems, for example,
this does not happen. As Chris says, Posix only promises to set errno
if there is an error indication. The only error indication for write
is a return of -1.
A portable way to check whether errno was set would be to do something
like
errno = 0;
if (write(...) != ...)
{
if (errno == 0)
error("unexpected short write--disk full?")
else
error("write failed: %s", strerror(errno));
}
Ian