stream: handle short writes

The write functionality is almost unused (only encoding 2-pass mode uses
it to write the log file). Moreover, it almost makes no sense to use
this in a not local scenario. This change is just to prevent people from
duplicating the short write logic across all streams that happen to
support writing. Mostly untested; local log file writing still works.
This commit is contained in:
wm4 2019-09-14 12:55:06 +02:00
parent ebab42c9a8
commit bec218c4ad
1 changed files with 10 additions and 7 deletions

View File

@ -419,15 +419,18 @@ struct bstr stream_peek(stream_t *s, int len)
int stream_write_buffer(stream_t *s, unsigned char *buf, int len)
{
int rd;
if (!s->write_buffer)
return -1;
rd = s->write_buffer(s, buf, len);
if (rd < 0)
return -1;
s->pos += rd;
assert(rd == len && "stream_write_buffer(): unexpected short write");
return rd;
int orig_len = len;
while (len) {
int w = s->write_buffer(s, buf, len);
if (w <= 0)
return -1;
s->pos += w;
buf += w;
len -= w;
}
return orig_len;
}
// Drop len bytes form input, possibly reading more until all is skipped. If