diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/io/src/get_line.c | 2 | ||||
-rw-r--r-- | lib/io/src/istream.c | 6 | ||||
-rw-r--r-- | lib/io/src/xfrm/istream.c | 7 | ||||
-rw-r--r-- | lib/io/test/istream_mem.c | 26 | ||||
-rw-r--r-- | lib/tar/src/iterator.c | 9 |
5 files changed, 21 insertions, 29 deletions
diff --git a/lib/io/src/get_line.c b/lib/io/src/get_line.c index a939a6c..94ae9ce 100644 --- a/lib/io/src/get_line.c +++ b/lib/io/src/get_line.c @@ -50,7 +50,7 @@ int istream_get_line(istream_t *strm, char **out, const sqfs_u8 *ptr; int ret; - ret = istream_get_buffered_data(strm, &ptr, &avail); + ret = istream_get_buffered_data(strm, &ptr, &avail, 0); if (ret < 0) goto fail_free; if (ret > 0) { diff --git a/lib/io/src/istream.c b/lib/io/src/istream.c index 6171f2c..b4c709c 100644 --- a/lib/io/src/istream.c +++ b/lib/io/src/istream.c @@ -19,7 +19,7 @@ sqfs_s32 istream_read(istream_t *strm, void *data, size_t size) size_t diff; int ret; - ret = istream_get_buffered_data(strm, &ptr, &diff); + ret = istream_get_buffered_data(strm, &ptr, &diff, size); if (ret > 0) break; if (ret < 0) @@ -48,7 +48,7 @@ int istream_skip(istream_t *strm, sqfs_u64 size) size_t diff; int ret; - ret = istream_get_buffered_data(strm, &ptr, &diff); + ret = istream_get_buffered_data(strm, &ptr, &diff, size); if (ret < 0) return ret; if (ret > 0) { @@ -81,7 +81,7 @@ sqfs_s32 istream_splice(istream_t *in, ostream_t *out, sqfs_u32 size) size_t diff; int ret; - ret = istream_get_buffered_data(in, &ptr, &diff); + ret = istream_get_buffered_data(in, &ptr, &diff, size); if (ret < 0) return ret; if (ret > 0) diff --git a/lib/io/src/xfrm/istream.c b/lib/io/src/xfrm/istream.c index 2ada5db..8755cb6 100644 --- a/lib/io/src/xfrm/istream.c +++ b/lib/io/src/xfrm/istream.c @@ -37,11 +37,8 @@ static int xfrm_precache(istream_t *base) const sqfs_u8 *ptr; size_t avail; - ret = istream_precache(xfrm->wrapped); - if (ret != 0) - return ret; - - ret = istream_get_buffered_data(xfrm->wrapped, &ptr, &avail); + ret = istream_get_buffered_data(xfrm->wrapped, &ptr, &avail, + sizeof(xfrm->uncompressed)); if (ret < 0) return ret; if (ret > 0) { diff --git a/lib/io/test/istream_mem.c b/lib/io/test/istream_mem.c index 632b1f5..f1849dd 100644 --- a/lib/io/test/istream_mem.c +++ b/lib/io/test/istream_mem.c @@ -32,8 +32,9 @@ static void init_buffer(void) int main(int argc, char **argv) { + size_t i, diff, size; bool eat_all = true; - size_t i, diff; + const sqfs_u8 *ptr; istream_t *in; int ret; (void)argc; (void)argv; @@ -45,33 +46,30 @@ int main(int argc, char **argv) TEST_EQUAL_UI(((sqfs_object_t *)in)->refcount, 1); TEST_STR_EQUAL(istream_get_filename(in), "memstream.txt"); - TEST_NOT_NULL(in->buffer); - TEST_EQUAL_UI(in->buffer_used, 0); for (i = 0; i < end2; i += diff) { - ret = istream_precache(in); + ret = istream_get_buffered_data(in, &ptr, &size, 61); TEST_EQUAL_I(ret, 0); if ((end2 - i) >= 61) { - TEST_NOT_NULL(in->buffer); - TEST_EQUAL_UI(in->buffer_used, 61); + TEST_NOT_NULL(ptr); + TEST_EQUAL_UI(size, 61); } else { - TEST_NOT_NULL(in->buffer); - TEST_EQUAL_UI(in->buffer_used, (end2 - i)); + TEST_NOT_NULL(ptr); + TEST_EQUAL_UI(size, (end2 - i)); } - for (size_t j = 0; j < in->buffer_used; ++j) { - TEST_EQUAL_UI(in->buffer[j], byte_at_offset(i + j)); + for (size_t j = 0; j < size; ++j) { + TEST_EQUAL_UI(ptr[j], byte_at_offset(i + j)); } - diff = eat_all ? in->buffer_used : (in->buffer_used / 2); + diff = eat_all ? size : (size / 2); eat_all = !eat_all; - in->buffer += diff; - in->buffer_used -= diff; + ret = istream_advance_buffer(in, diff); + TEST_EQUAL_I(ret, 0); } - TEST_EQUAL_UI(in->buffer_used, 0); sqfs_drop(in); return EXIT_SUCCESS; } diff --git a/lib/tar/src/iterator.c b/lib/tar/src/iterator.c index 66b5dfc..f46a9c2 100644 --- a/lib/tar/src/iterator.c +++ b/lib/tar/src/iterator.c @@ -132,7 +132,7 @@ static int strm_precache(istream_t *strm) int ret; ret = istream_get_buffered_data(tar->parent->stream, - &strm->buffer, &avail); + &strm->buffer, &avail, diff); if (ret > 0) goto fail_borked; if (ret < 0) @@ -373,11 +373,8 @@ dir_iterator_t *tar_open_stream(istream_t *strm) it->read_xattr = it_read_xattr; /* proble if the stream is compressed */ - ret = istream_precache(strm); - if (ret != 0) - goto out_strm; - - ret = istream_get_buffered_data(strm, &ptr, &size); + ret = istream_get_buffered_data(strm, &ptr, &size, + sizeof(tar_header_t)); if (ret != 0) goto out_strm; |