Skip to content

Commit

Permalink
Allow write to return less bytes than we asked for, or zero
Browse files Browse the repository at this point in the history
  • Loading branch information
lakeman committed Oct 31, 2014
1 parent 3a1828e commit 3b90753
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tfw_createfile.c
Expand Up @@ -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)
Expand Down

0 comments on commit 3b90753

Please sign in to comment.