Allow write to return less bytes than we asked for, or zero

This commit is contained in:
Jeremy Lakeman 2014-10-31 13:44:20 +10:30
parent 3a1828ec2a
commit 3b9075344f

View File

@ -114,7 +114,16 @@ int main(int argc, char **argv)
unsigned remain = size - offset - 1;
if (remain > sizeof buf)
remain = sizeof buf;
assert(fwrite(buf, remain, 1, stdout)==remain);
{
size_t off=0;
while(off<remain){
ssize_t wrote = fwrite(buf+off, 1, remain - off, stdout);
if (wrote<0)
fatal("write error: %s [errno=%d]", strerror(errno), errno);
off+=wrote;
}
}
assert(fputc('\n', stdout)!=EOF);
offset += remain + 1;
if (bounce <= n || bounce >= bouncemax)