aboutsummaryrefslogtreecommitdiff
path: root/lib/io/src/xfrm
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-09 13:43:50 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-09 13:43:50 +0200
commit9a4110f3c205107a3a48a0e48b760abf3cd1f3bc (patch)
tree0d89aec7c431487ebeb1254a36194acd0f837ee3 /lib/io/src/xfrm
parent5b1a81160a6d0e63ab1360e8777009b913464d89 (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/src/xfrm')
-rw-r--r--lib/io/src/xfrm/istream.c34
1 files changed, 19 insertions, 15 deletions
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;