aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-21 19:01:47 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-22 11:14:14 +0100
commitb4391c2c6e1d6a29ed4b8feed13a7f849e75bed9 (patch)
treefd7c791f41820772748d5c49ecfec00aa769cabe /lib
parent9071ddf137ea8a25de318161c2ed15345a5d5e6b (diff)
Ensure that tar2sqfs & sqfs2tar set stdin/out to binary mode
As usual, Windows has things different and is the platform where the problem was actually discovered. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/common/io_stdin.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/common/io_stdin.c b/lib/common/io_stdin.c
index dbdea5f..7abcd79 100644
--- a/lib/common/io_stdin.c
+++ b/lib/common/io_stdin.c
@@ -18,6 +18,7 @@ typedef struct {
const sparse_map_t *map;
sqfs_u64 offset;
sqfs_u64 size;
+ FILE *fp;
} sqfs_file_stdinout_t;
@@ -58,19 +59,19 @@ static int stdin_read_at(sqfs_file_t *base, sqfs_u64 offset,
return SQFS_ERROR_OUT_OF_BOUNDS;
while (size > 0) {
- if (ferror(stdin))
+ if (ferror(file->fp))
return SQFS_ERROR_IO;
- if (feof(stdin))
+ if (feof(file->fp))
return SQFS_ERROR_OUT_OF_BOUNDS;
if (offset > file->offset) {
diff = file->offset - offset;
diff = diff > (sqfs_u64)temp_size ? temp_size : diff;
- ret = fread(temp, 1, diff, stdin);
+ ret = fread(temp, 1, diff, file->fp);
} else {
- ret = fread(buffer, 1, size, stdin);
+ ret = fread(buffer, 1, size, file->fp);
}
if (offset <= file->offset) {
@@ -146,7 +147,8 @@ static int stdin_write_at(sqfs_file_t *base, sqfs_u64 offset,
return SQFS_ERROR_IO;
}
-sqfs_file_t *sqfs_get_stdin_file(const sparse_map_t *map, sqfs_u64 size)
+sqfs_file_t *sqfs_get_stdin_file(FILE *fp, const sparse_map_t *map,
+ sqfs_u64 size)
{
sqfs_file_stdinout_t *file = calloc(1, sizeof(*file));
sqfs_file_t *base = (sqfs_file_t *)file;
@@ -156,6 +158,7 @@ sqfs_file_t *sqfs_get_stdin_file(const sparse_map_t *map, sqfs_u64 size)
file->size = size;
file->map = map;
+ file->fp = fp;
base->destroy = stdinout_destroy;
base->write_at = stdin_write_at;