aboutsummaryrefslogtreecommitdiff
path: root/lib/io
diff options
context:
space:
mode:
Diffstat (limited to 'lib/io')
-rw-r--r--lib/io/Makemodule.am27
-rw-r--r--lib/io/src/get_line.c1
-rw-r--r--lib/io/src/internal.h1
-rw-r--r--lib/io/src/istream.c97
-rw-r--r--lib/io/src/mem.c1
-rw-r--r--lib/io/src/unix/istream.c1
-rw-r--r--lib/io/src/win32/istream.c1
-rw-r--r--lib/io/src/xfrm/istream.c1
-rw-r--r--lib/io/src/xfrm/ostream.c1
-rw-r--r--lib/io/test/istream_mem.c1
-rw-r--r--lib/io/test/istream_read.c105
-rw-r--r--lib/io/test/istream_skip.c94
-rw-r--r--lib/io/test/stream_splice.c98
-rw-r--r--lib/io/test/xfrm.c7
14 files changed, 21 insertions, 415 deletions
diff --git a/lib/io/Makemodule.am b/lib/io/Makemodule.am
index badaa99..9e442be 100644
--- a/lib/io/Makemodule.am
+++ b/lib/io/Makemodule.am
@@ -1,7 +1,7 @@
-libio_a_SOURCES = include/io/istream.h include/io/ostream.h include/io/xfrm.h \
+libio_a_SOURCES = include/io/istream.h include/io/xfrm.h \
include/io/file.h include/io/std.h include/io/dir_entry.h \
include/io/dir_iterator.h include/io/mem.h lib/io/src/internal.h \
- lib/io/src/istream.c lib/io/src/get_line.c lib/io/src/xfrm/ostream.c \
+ lib/io/src/get_line.c lib/io/src/xfrm/ostream.c \
lib/io/src/xfrm/istream.c lib/io/src/dir_tree_iterator.c \
lib/io/src/dir_entry.c lib/io/src/mem.c
libio_a_CFLAGS = $(AM_CFLAGS) $(ZLIB_CFLAGS) $(XZ_CFLAGS)
@@ -18,8 +18,7 @@ endif
noinst_LIBRARIES += libio.a
-LIBIO_TESTS = test_istream_mem test_get_line test_istream_read \
- test_istream_skip test_stream_splice test_dir_iterator \
+LIBIO_TESTS = test_istream_mem test_get_line test_dir_iterator \
test_dir_tree_iterator test_dir_tree_iterator2 test_dir_tree_iterator3
test_istream_mem_SOURCES = lib/io/test/istream_mem.c
@@ -30,15 +29,6 @@ test_get_line_SOURCES = lib/io/test/get_line.c
test_get_line_LDADD = libio.a libcompat.a
test_get_line_CPPFLAGS = $(AM_CPPFLAGS)
-test_istream_read_SOURCES = lib/io/test/istream_read.c
-test_istream_read_LDADD = libio.a libutil.a libcompat.a
-
-test_istream_skip_SOURCES = lib/io/test/istream_skip.c
-test_istream_skip_LDADD = libio.a libutil.a libcompat.a
-
-test_stream_splice_SOURCES = lib/io/test/stream_splice.c
-test_stream_splice_LDADD = libio.a libutil.a libcompat.a
-
test_dir_iterator_SOURCES = lib/io/test/dir_iterator.c
test_dir_iterator_LDADD = libio.a libutil.a libcompat.a
test_dir_iterator_CPPFLAGS = $(AM_CPPFLAGS)
@@ -61,7 +51,7 @@ test_dir_tree_iterator3_CPPFLAGS += -DTESTPATH=$(top_srcdir)/lib/io/test/testdir
if WITH_XZ
test_io_xfrm_xz_SOURCES = lib/io/test/xfrm.c
-test_io_xfrm_xz_LDADD = libio.a libxfrm.a libcompat.a $(XZ_LIBS)
+test_io_xfrm_xz_LDADD = libsquashfs.la libio.a libxfrm.a libcompat.a $(XZ_LIBS)
test_io_xfrm_xz_CPPFLAGS = $(AM_CPPFLAGS) -DDO_XZ=1
LIBIO_TESTS += test_io_xfrm_xz
@@ -69,7 +59,8 @@ endif
if WITH_BZIP2
test_io_xfrm_bzip2_SOURCES = lib/io/test/xfrm.c
-test_io_xfrm_bzip2_LDADD = libio.a libxfrm.a libcompat.a $(BZIP2_LIBS)
+test_io_xfrm_bzip2_LDADD = libsquashfs.la libio.a libxfrm.a \
+ libcompat.a $(BZIP2_LIBS)
test_io_xfrm_bzip2_CPPFLAGS = $(AM_CPPFLAGS) -DDO_BZIP2=1
LIBIO_TESTS += test_io_xfrm_bzip2
@@ -77,7 +68,8 @@ endif
if WITH_GZIP
test_io_xfrm_gzip_SOURCES = lib/io/test/xfrm.c
-test_io_xfrm_gzip_LDADD = libio.a libxfrm.a libcompat.a $(ZLIB_LIBS)
+test_io_xfrm_gzip_LDADD = libsquashfs.la libio.a libxfrm.a \
+ libcompat.a $(ZLIB_LIBS)
test_io_xfrm_gzip_CPPFLAGS = $(AM_CPPFLAGS) -DDO_GZIP=1
LIBIO_TESTS += test_io_xfrm_gzip
@@ -86,7 +78,8 @@ endif
if WITH_ZSTD
if HAVE_ZSTD_STREAM
test_io_xfrm_zstd_SOURCES = lib/io/test/xfrm.c
-test_io_xfrm_zstd_LDADD = libio.a libxfrm.a libcompat.a $(ZSTD_LIBS)
+test_io_xfrm_zstd_LDADD = libsquashfs.la libio.a libxfrm.a \
+ libcompat.a $(ZSTD_LIBS)
test_io_xfrm_zstd_CPPFLAGS = $(AM_CPPFLAGS) -DDO_ZSTD=1
LIBIO_TESTS += test_io_xfrm_zstd
diff --git a/lib/io/src/get_line.c b/lib/io/src/get_line.c
index 9ab4928..ad37be6 100644
--- a/lib/io/src/get_line.c
+++ b/lib/io/src/get_line.c
@@ -5,6 +5,7 @@
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "internal.h"
+#include "sqfs/io.h"
static void ltrim(char *buffer)
{
diff --git a/lib/io/src/internal.h b/lib/io/src/internal.h
index 1e51012..e010727 100644
--- a/lib/io/src/internal.h
+++ b/lib/io/src/internal.h
@@ -10,7 +10,6 @@
#include "config.h"
#include "compat.h"
#include "io/istream.h"
-#include "io/ostream.h"
#include "io/file.h"
#include "io/xfrm.h"
#include "io/std.h"
diff --git a/lib/io/src/istream.c b/lib/io/src/istream.c
deleted file mode 100644
index 6fbc67b..0000000
--- a/lib/io/src/istream.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * istream.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "internal.h"
-
-
-sqfs_s32 istream_read(sqfs_istream_t *strm, void *data, size_t size)
-{
- sqfs_s32 total = 0;
-
- if (size > 0x7FFFFFFF)
- size = 0x7FFFFFFF;
-
- while (size > 0) {
- const sqfs_u8 *ptr;
- size_t diff;
- int ret;
-
- ret = strm->get_buffered_data(strm, &ptr, &diff, size);
- if (ret > 0)
- break;
- if (ret < 0)
- return ret;
-
- if (diff > size)
- diff = size;
-
- memcpy(data, ptr, diff);
- strm->advance_buffer(strm, diff);
- data = (char *)data + diff;
- size -= diff;
- total += diff;
- }
-
- return total;
-}
-
-int istream_skip(sqfs_istream_t *strm, sqfs_u64 size)
-{
- while (size > 0) {
- const sqfs_u8 *ptr;
- size_t diff;
- int ret;
-
- ret = strm->get_buffered_data(strm, &ptr, &diff, size);
- if (ret < 0)
- return ret;
- if (ret > 0) {
- fprintf(stderr, "%s: unexpected end-of-file\n",
- strm->get_filename(strm));
- return -1;
- }
-
- if ((sqfs_u64)diff > size)
- diff = size;
-
- size -= diff;
- strm->advance_buffer(strm, diff);
- }
-
- return 0;
-}
-
-sqfs_s32 istream_splice(sqfs_istream_t *in, sqfs_ostream_t *out, sqfs_u32 size)
-{
- sqfs_s32 total = 0;
-
- if (size > 0x7FFFFFFF)
- size = 0x7FFFFFFF;
-
- while (size > 0) {
- const sqfs_u8 *ptr;
- size_t diff;
- int ret;
-
- ret = in->get_buffered_data(in, &ptr, &diff, size);
- if (ret < 0)
- return ret;
- if (ret > 0)
- break;
-
- if (diff > size)
- diff = size;
-
- if (out->append(out, ptr, diff))
- return -1;
-
- total += diff;
- size -= diff;
- in->advance_buffer(in, diff);
- }
-
- return total;
-}
diff --git a/lib/io/src/mem.c b/lib/io/src/mem.c
index 435a169..7150d1f 100644
--- a/lib/io/src/mem.c
+++ b/lib/io/src/mem.c
@@ -7,6 +7,7 @@
#include "config.h"
#include "io/mem.h"
#include "compat.h"
+#include "sqfs/io.h"
#include <stdlib.h>
#include <string.h>
diff --git a/lib/io/src/unix/istream.c b/lib/io/src/unix/istream.c
index fc76bab..39d570f 100644
--- a/lib/io/src/unix/istream.c
+++ b/lib/io/src/unix/istream.c
@@ -5,6 +5,7 @@
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "../internal.h"
+#include "sqfs/io.h"
typedef struct {
sqfs_istream_t base;
diff --git a/lib/io/src/win32/istream.c b/lib/io/src/win32/istream.c
index 223b20d..e6cb266 100644
--- a/lib/io/src/win32/istream.c
+++ b/lib/io/src/win32/istream.c
@@ -5,6 +5,7 @@
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "../internal.h"
+#include "sqfs/io.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
diff --git a/lib/io/src/xfrm/istream.c b/lib/io/src/xfrm/istream.c
index 5c23d28..c499f6c 100644
--- a/lib/io/src/xfrm/istream.c
+++ b/lib/io/src/xfrm/istream.c
@@ -5,6 +5,7 @@
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "../internal.h"
+#include "sqfs/io.h"
typedef struct istream_xfrm_t {
sqfs_istream_t base;
diff --git a/lib/io/src/xfrm/ostream.c b/lib/io/src/xfrm/ostream.c
index 81c19dd..4c77f42 100644
--- a/lib/io/src/xfrm/ostream.c
+++ b/lib/io/src/xfrm/ostream.c
@@ -5,6 +5,7 @@
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "../internal.h"
+#include "sqfs/io.h"
typedef struct ostream_xfrm_t {
sqfs_ostream_t base;
diff --git a/lib/io/test/istream_mem.c b/lib/io/test/istream_mem.c
index f364fd3..d5e0c2c 100644
--- a/lib/io/test/istream_mem.c
+++ b/lib/io/test/istream_mem.c
@@ -8,6 +8,7 @@
#include "util/test.h"
#include "io/mem.h"
+#include "sqfs/io.h"
static const size_t end0 = 449; /* region 1: filled with 'A' */
static const size_t end1 = 521; /* region 2: filled with 'B' */
diff --git a/lib/io/test/istream_read.c b/lib/io/test/istream_read.c
deleted file mode 100644
index 66fec4b..0000000
--- a/lib/io/test/istream_read.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * istream_read.c
- *
- * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include "io/istream.h"
-#include "util/test.h"
-#include "io/mem.h"
-
-static const sqfs_u64 end0 = 449; /* region 1: filled with 'A' */
-static const sqfs_u64 end1 = 521; /* region 2: filled with 'B' */
-static const sqfs_u64 end2 = 941; /* region 3: filled with 'C' */
-
-static sqfs_u8 rd_buffer[941];
-
-static sqfs_u8 byte_at_offset(sqfs_u64 off)
-{
- if (off < end0)
- return 'A';
- if (off < end1)
- return 'B';
- return 'C';
-}
-
-static void init_rd_buffer(void)
-{
- for (size_t i = 0; i < end2; ++i)
- rd_buffer[i] = byte_at_offset(i);
-}
-
-int main(int argc, char **argv)
-{
- sqfs_u8 read_buffer[61];
- sqfs_u64 read_off = 0;
- sqfs_istream_t *dummy;
- (void)argc; (void)argv;
-
- init_rd_buffer();
- dummy = istream_memory_create("dummy file", 103,
- rd_buffer, sizeof(rd_buffer));
- TEST_NOT_NULL(dummy);
-
- /* region 1 */
- while (read_off < end0) {
- size_t read_diff = end0 - read_off;
-
- if (read_diff > sizeof(read_buffer))
- read_diff = sizeof(read_buffer);
-
- int ret = istream_read(dummy, read_buffer, read_diff);
- TEST_ASSERT(ret > 0);
- TEST_ASSERT((size_t)ret <= read_diff);
-
- for (int i = 0; i < ret; ++i) {
- TEST_EQUAL_UI(read_buffer[i], 'A');
- }
-
- read_off += ret;
- }
-
- /* region 2 */
- while (read_off < end1) {
- size_t read_diff = end1 - read_off;
-
- if (read_diff > sizeof(read_buffer))
- read_diff = sizeof(read_buffer);
-
- int ret = istream_read(dummy, read_buffer, read_diff);
- TEST_ASSERT(ret > 0);
- TEST_ASSERT((size_t)ret <= read_diff);
-
- for (int i = 0; i < ret; ++i) {
- TEST_EQUAL_UI(read_buffer[i], 'B');
- }
-
- read_off += ret;
- }
-
- /* region 3 */
- for (;;) {
- size_t read_diff = sizeof(read_buffer);
-
- int ret = istream_read(dummy, read_buffer, read_diff);
- TEST_ASSERT(ret >= 0);
- TEST_ASSERT((size_t)ret <= read_diff);
-
- if (ret == 0) {
- TEST_EQUAL_UI(read_off, end2);
- break;
- }
-
- for (int i = 0; i < ret; ++i) {
- TEST_EQUAL_UI(read_buffer[i], 'C');
- }
-
- read_off += ret;
- TEST_ASSERT(read_off <= end2);
- }
-
- sqfs_drop(dummy);
- return EXIT_SUCCESS;
-}
diff --git a/lib/io/test/istream_skip.c b/lib/io/test/istream_skip.c
deleted file mode 100644
index 0fc3e11..0000000
--- a/lib/io/test/istream_skip.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * istream_skip.c
- *
- * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include "io/istream.h"
-#include "util/test.h"
-#include "io/mem.h"
-
-static const sqfs_u64 end0 = 449; /* region 1: filled with 'A' */
-static const sqfs_u64 end1 = 521; /* region 2: filled with 'B' */
-static const sqfs_u64 end2 = 941; /* region 3: filled with 'C' */
-
-static sqfs_u8 rd_buffer[941];
-
-static sqfs_u8 byte_at_offset(sqfs_u64 off)
-{
- if (off < end0)
- return 'A';
- if (off < end1)
- return 'B';
- return 'C';
-}
-
-static void init_rd_buffer(void)
-{
- for (size_t i = 0; i < end2; ++i)
- rd_buffer[i] = byte_at_offset(i);
-}
-
-int main(int argc, char **argv)
-{
- sqfs_u8 read_buffer[61];
- sqfs_u64 read_off = 0;
- sqfs_istream_t *dummy;
- (void)argc; (void)argv;
-
- init_rd_buffer();
- dummy = istream_memory_create("dummy file", 103,
- rd_buffer, sizeof(rd_buffer));
- TEST_NOT_NULL(dummy);
-
- /* region 1 */
- while (read_off < end0) {
- size_t read_diff = end0 - read_off;
-
- if (read_diff > sizeof(read_buffer))
- read_diff = sizeof(read_buffer);
-
- int ret = istream_read(dummy, read_buffer, read_diff);
- TEST_ASSERT(ret > 0);
- TEST_ASSERT((size_t)ret <= read_diff);
-
- for (int i = 0; i < ret; ++i) {
- TEST_EQUAL_UI(read_buffer[i], 'A');
- }
-
- read_off += ret;
- }
-
- /* region 2 */
- {
- int ret = istream_skip(dummy, end2 - end1);
- TEST_EQUAL_I(ret, 0);
- read_off += (end2 - end1);
- }
-
- /* region 3 */
- for (;;) {
- size_t read_diff = sizeof(read_buffer);
-
- int ret = istream_read(dummy, read_buffer, read_diff);
- TEST_ASSERT(ret >= 0);
- TEST_ASSERT((size_t)ret <= read_diff);
-
- if (ret == 0) {
- TEST_EQUAL_UI(read_off, end2);
- break;
- }
-
- for (int i = 0; i < ret; ++i) {
- TEST_EQUAL_UI(read_buffer[i], 'C');
- }
-
- read_off += ret;
- TEST_ASSERT(read_off <= end2);
- }
-
- sqfs_drop(dummy);
- return EXIT_SUCCESS;
-}
diff --git a/lib/io/test/stream_splice.c b/lib/io/test/stream_splice.c
deleted file mode 100644
index a9edd76..0000000
--- a/lib/io/test/stream_splice.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * stream_splice.c
- *
- * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include "io/istream.h"
-#include "io/ostream.h"
-#include "io/mem.h"
-#include "util/test.h"
-
-static const sqfs_u64 end0 = 449; /* region 1: filled with 'A' */
-static const sqfs_u64 end1 = 521; /* region 2: filled with 'B' */
-static const sqfs_u64 end2 = 941; /* region 3: filled with 'C' */
-
-static sqfs_u8 rd_buffer[941];
-
-static sqfs_u8 byte_at_offset(sqfs_u64 off)
-{
- if (off < end0)
- return 'A';
- if (off < end1)
- return 'B';
- return 'C';
-}
-
-static void init_rd_buffer(void)
-{
- for (size_t i = 0; i < end2; ++i)
- rd_buffer[i] = byte_at_offset(i);
-}
-
-/*****************************************************************************/
-
-static int out_append(sqfs_ostream_t *strm, const void *data, size_t size);
-
-static sqfs_u64 out_offset = 0;
-
-static sqfs_ostream_t out = {
- { 1, NULL, NULL },
- out_append,
- NULL,
- NULL,
- NULL,
-};
-
-static int out_append(sqfs_ostream_t *strm, const void *data, size_t size)
-{
- const sqfs_u8 *ptr = data;
-
- TEST_ASSERT(strm == &out);
- TEST_ASSERT(size > 0);
-
- while (size--) {
- sqfs_u8 x = *(ptr++);
- sqfs_u8 y = byte_at_offset(out_offset++);
-
- TEST_EQUAL_UI(x, y);
- TEST_ASSERT(out_offset <= end2);
- }
-
- return 0;
-}
-
-/*****************************************************************************/
-
-int main(int argc, char **argv)
-{
- sqfs_u64 total = 0;
- sqfs_istream_t *in;
- sqfs_s32 ret;
- (void)argc; (void)argv;
-
- init_rd_buffer();
- in = istream_memory_create("memory_in", 109,
- rd_buffer, sizeof(rd_buffer));
- TEST_NOT_NULL(in);
-
- for (;;) {
- ret = istream_splice(in, &out, 211);
- TEST_ASSERT(ret >= 0);
-
- if (ret == 0)
- break;
-
- total += ret;
- TEST_ASSERT(total <= end2);
- TEST_ASSERT(out_offset <= end2);
- TEST_EQUAL_UI(total, out_offset);
- }
-
- TEST_EQUAL_UI(total, end2);
- TEST_EQUAL_UI(out_offset, end2);
- sqfs_drop(in);
- return EXIT_SUCCESS;
-}
diff --git a/lib/io/test/xfrm.c b/lib/io/test/xfrm.c
index 1b48e6f..b871610 100644
--- a/lib/io/test/xfrm.c
+++ b/lib/io/test/xfrm.c
@@ -7,6 +7,7 @@
#include "xfrm/compress.h"
#include "xfrm/stream.h"
#include "util/test.h"
+#include "sqfs/io.h"
#include "io/xfrm.h"
#include "io/mem.h"
@@ -430,15 +431,15 @@ static void run_unpack_test(const void *blob, size_t size)
TEST_EQUAL_UI(((sqfs_object_t *)mem_istream)->refcount, 2);
for (i = 0; i < (sizeof(orig) - 1); ++i) {
- ret = istream_read(istream, &c, 1);
+ ret = sqfs_istream_read(istream, &c, 1);
TEST_EQUAL_I(ret, 1);
TEST_EQUAL_I(c, orig[i]);
}
- ret = istream_read(istream, &c, 1);
+ ret = sqfs_istream_read(istream, &c, 1);
TEST_EQUAL_I(ret, 0);
- ret = istream_read(istream, &c, 1);
+ ret = sqfs_istream_read(istream, &c, 1);
TEST_EQUAL_I(ret, 0);
sqfs_drop(istream);