mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 09:26:37 +00:00
Allow write to return less bytes than we asked for, or zero
This commit is contained in:
parent
3a1828ec2a
commit
3b9075344f
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user