aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-04 15:40:29 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-04 15:40:29 +0200
commit8af4ee6f415fe316894e4423235dfc4ee70d8cbb (patch)
treeeb0cb6e236276e3bfa39aff7c7b2ec771ee8d171 /lib
parent723306c417b3b0f8e6a3904906d6c5612cace432 (diff)
libio: move splice function from ostream to istream
It touches internals of the istream, particularly the buffer, but not of the ostream. It really belongs to istream_t. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/io/src/istream.c32
-rw-r--r--lib/io/src/ostream.c33
-rw-r--r--lib/io/test/stream_splice.c2
3 files changed, 33 insertions, 34 deletions
diff --git a/lib/io/src/istream.c b/lib/io/src/istream.c
index 051fac8..2b89a00 100644
--- a/lib/io/src/istream.c
+++ b/lib/io/src/istream.c
@@ -64,3 +64,35 @@ int istream_skip(istream_t *strm, sqfs_u64 size)
return 0;
}
+
+sqfs_s32 istream_splice(istream_t *in, ostream_t *out, sqfs_u32 size)
+{
+ sqfs_s32 total = 0;
+ size_t diff;
+
+ if (size > 0x7FFFFFFF)
+ size = 0x7FFFFFFF;
+
+ while (size > 0) {
+ if (in->buffer_offset >= in->buffer_used) {
+ if (istream_precache(in))
+ return -1;
+
+ if (in->buffer_used == 0)
+ break;
+ }
+
+ diff = in->buffer_used - in->buffer_offset;
+ if (diff > size)
+ diff = size;
+
+ if (ostream_append(out, in->buffer + in->buffer_offset, diff))
+ return -1;
+
+ in->buffer_offset += diff;
+ size -= diff;
+ total += diff;
+ }
+
+ return total;
+}
diff --git a/lib/io/src/ostream.c b/lib/io/src/ostream.c
index da0b7b3..35f98d4 100644
--- a/lib/io/src/ostream.c
+++ b/lib/io/src/ostream.c
@@ -33,36 +33,3 @@ int ostream_append_sparse(ostream_t *strm, size_t size)
return strm->append_sparse(strm, size);
}
-
-sqfs_s32 ostream_append_from_istream(ostream_t *out, istream_t *in,
- sqfs_u32 size)
-{
- sqfs_s32 total = 0;
- size_t diff;
-
- if (size > 0x7FFFFFFF)
- size = 0x7FFFFFFF;
-
- while (size > 0) {
- if (in->buffer_offset >= in->buffer_used) {
- if (istream_precache(in))
- return -1;
-
- if (in->buffer_used == 0)
- break;
- }
-
- diff = in->buffer_used - in->buffer_offset;
- if (diff > size)
- diff = size;
-
- if (out->append(out, in->buffer + in->buffer_offset, diff))
- return -1;
-
- in->buffer_offset += diff;
- size -= diff;
- total += diff;
- }
-
- return total;
-}
diff --git a/lib/io/test/stream_splice.c b/lib/io/test/stream_splice.c
index 5379b39..9008d83 100644
--- a/lib/io/test/stream_splice.c
+++ b/lib/io/test/stream_splice.c
@@ -79,7 +79,7 @@ int main(int argc, char **argv)
TEST_NOT_NULL(in);
for (;;) {
- ret = ostream_append_from_istream(&out, in, 211);
+ ret = istream_splice(in, &out, 211);
TEST_ASSERT(ret >= 0);
if (ret == 0)