From 9a4110f3c205107a3a48a0e48b760abf3cd1f3bc Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 9 Jun 2023 13:43:50 +0200 Subject: libio: eliminate direct access of the interal buffer Instead, go through helper functions, which in a next step can be moved inside the implementation. Signed-off-by: David Oberhollenzer --- lib/io/src/xfrm/istream.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'lib/io/src/xfrm') diff --git a/lib/io/src/xfrm/istream.c b/lib/io/src/xfrm/istream.c index 152563f..a89ac3d 100644 --- a/lib/io/src/xfrm/istream.c +++ b/lib/io/src/xfrm/istream.c @@ -18,7 +18,7 @@ typedef struct istream_xfrm_t { static int xfrm_precache(istream_t *base) { istream_xfrm_t *xfrm = (istream_xfrm_t *)base; - int ret; + int ret, sret; if (base->eof) return 0; @@ -34,20 +34,26 @@ static int xfrm_precache(istream_t *base) base->buffer = xfrm->uncompressed; - ret = istream_precache(xfrm->wrapped); - if (ret != 0) - return ret; - for (;;) { sqfs_u32 in_off = 0, out_off = base->buffer_used; int mode = XFRM_STREAM_FLUSH_NONE; + const sqfs_u8 *ptr; + size_t avail; + + ret = istream_precache(xfrm->wrapped); + if (ret != 0) + return ret; - if (xfrm->wrapped->eof) + ret = istream_get_buffered_data(xfrm->wrapped, &ptr, &avail); + if (ret < 0) + return ret; + if (ret > 0) { mode = XFRM_STREAM_FLUSH_FULL; + avail = 0; + } ret = xfrm->xfrm->process_data(xfrm->xfrm, - xfrm->wrapped->buffer, - xfrm->wrapped->buffer_used, + ptr, avail, xfrm->uncompressed + out_off, BUFSZ - out_off, &in_off, &out_off, mode); @@ -59,17 +65,15 @@ static int xfrm_precache(istream_t *base) } base->buffer_used = out_off; - xfrm->wrapped->buffer += in_off; - xfrm->wrapped->buffer_used -= in_off; + + sret = istream_advance_buffer(xfrm->wrapped, in_off); + if (sret != 0) + return sret; if (ret == XFRM_STREAM_BUFFER_FULL || out_off >= BUFSZ) break; - ret = istream_precache(xfrm->wrapped); - if (ret != 0) - return ret; - - if (xfrm->wrapped->eof && xfrm->wrapped->buffer_used == 0) { + if (mode == XFRM_STREAM_FLUSH_FULL) { if (base->buffer_used == 0) base->eof = true; break; -- cgit v1.2.3