len = 0;
} else
len = get_line(*b, *avail, nl);
+
/*
* Read bytes more while it does not reach the end of line.
*/
- while (*nl == 0 && len == *avail && !quit && *nbytes_read < UUENCODE_BID_MAX_READ) {
+ while (*nl == 0 && len == *avail && !quit &&
+ *nbytes_read < UUENCODE_BID_MAX_READ) {
ssize_t diff = *ravail - *avail;
+ size_t nbytes_req = (*ravail+1023) & ~1023U;
+ ssize_t tested;
+
+ /* Increase reading bytes if it is not enough to at least
+ * new two lines. */
+ if (nbytes_req < (size_t)*ravail + 160)
+ nbytes_req <<= 1;
- *b = __archive_read_filter_ahead(filter, 160 + *ravail, avail);
+ *b = __archive_read_filter_ahead(filter, nbytes_req, avail);
if (*b == NULL) {
if (*ravail >= *avail)
return (0);
- /* Reading bytes reaches the end of file. */
+ /* Reading bytes reaches the end of a stream. */
*b = __archive_read_filter_ahead(filter, *avail, avail);
quit = 1;
}
*ravail = *avail;
*b += diff;
*avail -= diff;
- len = get_line(*b, *avail, nl);
+ tested = len;/* Skip some bytes we already determinated. */
+ len = get_line(*b + tested, *avail - tested, nl);
+ if (len >= 0)
+ len += tested;
}
return (len);
}