aboutsummaryrefslogtreecommitdiff
path: root/lib/io/test
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-12 18:32:12 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-15 13:38:25 +0200
commiteb9a4b9034453ae3093d678a6f3898303dc5a5a0 (patch)
treecd024b5ff5e1c77400a561adee50522f10fdadcd /lib/io/test
parent63bc750fecb00fc5878ca889204fc65510893778 (diff)
libio: remove ostream_append_sparse and fallback implementation
Instead of a separate append-sparse function, simply accept NULL as an input for append. For both Unix and Win32, a fallback needs to be implemented. For XFRM, we can just memset the input buffer to zero, same for the libsquashfs data writer. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/test')
-rw-r--r--lib/io/test/sparse_fb.c66
-rw-r--r--lib/io/test/xfrm.c10
2 files changed, 6 insertions, 70 deletions
diff --git a/lib/io/test/sparse_fb.c b/lib/io/test/sparse_fb.c
deleted file mode 100644
index 5ee6004..0000000
--- a/lib/io/test/sparse_fb.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * get_line.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-
-#include "io/ostream.h"
-#include "util/test.h"
-#include "util/util.h"
-
-static ostream_t dummy;
-static size_t total = 0;
-
-static int dummy_append(ostream_t *strm, const void *data, size_t size)
-{
- bool bret;
-
- TEST_ASSERT(strm == &dummy);
- TEST_NOT_NULL(data);
- TEST_ASSERT(size > 0);
-
- bret = is_memory_zero(data, size);
- TEST_ASSERT(bret);
-
- bret = SZ_ADD_OV(total, size, &total);
- TEST_ASSERT(!bret);
- return 0;
-}
-
-static int dummy_flush(ostream_t *strm)
-{
- TEST_ASSERT(strm == &dummy);
- return 0;
-}
-
-static ostream_t dummy = {
- {
- 1,
- NULL,
- NULL,
- },
- dummy_append,
- NULL,
- dummy_flush,
- NULL,
-};
-
-int main(int argc, char **argv)
-{
- size_t ref;
- int ret;
- (void)argc; (void)argv;
-
- ref = 131072 + 1337;
-
- ret = ostream_append_sparse(&dummy, ref);
- TEST_EQUAL_I(ret, 0);
-
- ret = dummy.flush(&dummy);
- TEST_EQUAL_I(ret, 0);
-
- TEST_EQUAL_UI(ref, total);
- return EXIT_SUCCESS;
-}
diff --git a/lib/io/test/xfrm.c b/lib/io/test/xfrm.c
index c2e450c..184db9e 100644
--- a/lib/io/test/xfrm.c
+++ b/lib/io/test/xfrm.c
@@ -374,7 +374,6 @@ static int mem_flush(ostream_t *strm);
static ostream_t mem_ostream = {
{ 1, NULL, NULL, },
mem_append,
- NULL,
mem_flush,
NULL,
};
@@ -382,15 +381,18 @@ static ostream_t mem_ostream = {
static int mem_append(ostream_t *strm, const void *data, size_t size)
{
TEST_ASSERT(strm == &mem_ostream);
- TEST_NOT_NULL(data);
TEST_ASSERT(size > 0);
TEST_ASSERT(mo_written <= sizeof(mo_buffer));
TEST_ASSERT(size <= (sizeof(mo_buffer) - mo_written));
- memcpy(mo_buffer + mo_written, data, size);
- mo_written += size;
+ if (data == NULL) {
+ memset(mo_buffer + mo_written, 0, size);
+ } else {
+ memcpy(mo_buffer + mo_written, data, size);
+ }
+ mo_written += size;
return 0;
}