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/win32/istream.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/io/src/win32') diff --git a/lib/io/src/win32/istream.c b/lib/io/src/win32/istream.c index be3d829..918b868 100644 --- a/lib/io/src/win32/istream.c +++ b/lib/io/src/win32/istream.c @@ -23,6 +23,21 @@ static int file_precache(istream_t *strm) DWORD diff, actual; HANDLE hnd; + if (strm->buffer_offset >= strm->buffer_used) { + strm->buffer_offset = 0; + strm->buffer_used = 0; + } else if (strm->buffer_offset > 0) { + memmove(strm->buffer, + strm->buffer + strm->buffer_offset, + strm->buffer_used - strm->buffer_offset); + + strm->buffer_used -= strm->buffer_offset; + strm->buffer_offset = 0; + } + + if (strm->eof) + return 0; + hnd = file->path == NULL ? GetStdHandle(STD_INPUT_HANDLE) : file->hnd; while (strm->buffer_used < sizeof(file->buffer)) { -- cgit v1.2.3