aboutsummaryrefslogtreecommitdiff
path: root/lib/io/src/unix
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-04 14:36:25 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-04 15:09:05 +0200
commit723306c417b3b0f8e6a3904906d6c5612cace432 (patch)
tree34235c4e6e11a1702e61d81f4f58bc9f3da57c58 /lib/io/src/unix
parent061fbc12fe49ff49088a644def3227d3800cd8a7 (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/src/unix')
-rw-r--r--lib/io/src/unix/istream.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/io/src/unix/istream.c b/lib/io/src/unix/istream.c
index f8cffad..24b18d6 100644
--- a/lib/io/src/unix/istream.c
+++ b/lib/io/src/unix/istream.c
@@ -20,15 +20,25 @@ static int file_precache(istream_t *strm)
ssize_t ret;
size_t diff;
- while (strm->buffer_used < sizeof(file->buffer)) {
+ 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;
+ }
+
+ while (!strm->eof && strm->buffer_used < sizeof(file->buffer)) {
diff = sizeof(file->buffer) - strm->buffer_used;
ret = read(file->fd, strm->buffer + strm->buffer_used, diff);
- if (ret == 0) {
+ if (ret == 0)
strm->eof = true;
- break;
- }
if (ret < 0) {
if (errno == EINTR)