From 3a851dfe87c88ac1d4dddc2a26cc48b037f852f9 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 8 Sep 2019 14:53:30 +0200 Subject: Replace direct file I/O with abstraction layer This should make it easier to use libsquashfs with custom setups that embedd a squashfs image inside something else. Also, it should make it easier to port to non unix-like platforms. Signed-off-by: David Oberhollenzer --- lib/util/padd_file.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/util') diff --git a/lib/util/padd_file.c b/lib/util/padd_file.c index 9a2428d..21950b4 100644 --- a/lib/util/padd_file.c +++ b/lib/util/padd_file.c @@ -6,6 +6,7 @@ */ #include "config.h" +#include "sqfs/io.h" #include "util.h" #include @@ -39,3 +40,32 @@ fail_errno: perror("padding output file to block size"); goto out; } + +int padd_sqfs(sqfs_file_t *file, uint64_t size, size_t blocksize) +{ + size_t padd_sz = size % blocksize; + int status = -1; + uint8_t *buffer; + + if (padd_sz == 0) + return 0; + + padd_sz = blocksize - padd_sz; + + buffer = calloc(1, padd_sz); + if (buffer == NULL) + goto fail_errno; + + if (file->write_at(file, file->get_size(file), + buffer, padd_sz)) { + goto fail_errno; + } + + status = 0; +out: + free(buffer); + return status; +fail_errno: + perror("padding output file to block size"); + goto out; +} -- cgit v1.2.3