{
struct tip_subbuf *ts;
struct stat sb;
- unsigned int ready;
+ unsigned int ready, this_size;
int err;
if (fstat(tip->fd, &sb) < 0) {
if (!ready)
return 0;
+ this_size = buf_size;
while (ready) {
+ if (this_size > ready)
+ this_size = ready;
+
ts = malloc(sizeof(*ts));
ts->max_len = maxlen;
ts->buf = NULL;
- ts->len = buf_size;
+ ts->len = this_size;
ts->max_len = ts->len;
ts->offset = tip->ofile_offset;
tip->ofile_offset += ts->len;
if (err)
return err;
- ready -= buf_size;
+ ready -= this_size;
}
return 0;
tip->ofile_stdout = 0;
tip->ofile_mmap = 0;
vbuf_size = 0;
+ mode = 0; /* gcc 4.x issues a bogus warning */
} else if (pipeline) {
tip->ofile = fdopen(STDOUT_FILENO, "w");
tip->ofile_stdout = 1;