From 723306c417b3b0f8e6a3904906d6c5612cace432 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 4 Jun 2023 14:36:25 +0200 Subject: libio: Move istream_t precache logic into backend implementation The end goal is to remove direct buffer access from the istream_t interfaces and make that opaque. For the tar implementation, this already safes us needless buffer copying, as we essentially allow the user to read-through from the underlying stream. Signed-off-by: David Oberhollenzer --- lib/io/src/xfrm/istream.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/io/src/xfrm/istream.c') diff --git a/lib/io/src/xfrm/istream.c b/lib/io/src/xfrm/istream.c index 4a1ad77..b301209 100644 --- a/lib/io/src/xfrm/istream.c +++ b/lib/io/src/xfrm/istream.c @@ -20,6 +20,21 @@ static int xfrm_precache(istream_t *base) istream_xfrm_t *xfrm = (istream_xfrm_t *)base; int ret; + if (base->buffer_offset >= base->buffer_used) { + base->buffer_offset = 0; + base->buffer_used = 0; + } else if (base->buffer_offset > 0) { + memmove(base->buffer, + base->buffer + base->buffer_offset, + base->buffer_used - base->buffer_offset); + + base->buffer_used -= base->buffer_offset; + base->buffer_offset = 0; + } + + if (base->eof) + return 0; + ret = istream_precache(xfrm->wrapped); if (ret != 0) return ret; -- cgit v1.2.3