diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-09-13 13:37:42 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-09-16 09:34:35 +0200 |
commit | f757737060d4daebb24a32e90d912661428708a8 (patch) | |
tree | a6e96145d4fc540e435c13a69c924329db2edb6d /lib/tar/read_header.c | |
parent | c1a2cb729bd5bb5fdadf00cb3968bbc541f79750 (diff) |
Remodel libtar/tar2sqfs to read data from an istream_t
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/tar/read_header.c')
-rw-r--r-- | lib/tar/read_header.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/tar/read_header.c b/lib/tar/read_header.c index 14752ea..b332514 100644 --- a/lib/tar/read_header.c +++ b/lib/tar/read_header.c @@ -170,20 +170,24 @@ static int decode_header(const tar_header_t *hdr, unsigned int set_by_pax, return 0; } -int read_header(FILE *fp, tar_header_decoded_t *out) +int read_header(istream_t *fp, tar_header_decoded_t *out) { unsigned int set_by_pax = 0; bool prev_was_zero = false; sqfs_u64 pax_size; tar_header_t hdr; - int version; + int version, ret; memset(out, 0, sizeof(*out)); for (;;) { - if (read_retry("reading tar header", fp, &hdr, sizeof(hdr))) + ret = istream_read(fp, &hdr, sizeof(hdr)); + if (ret < 0) goto fail; + if ((size_t)ret < sizeof(hdr)) + goto out_eof; + if (is_zero_block(&hdr)) { if (prev_was_zero) goto out_eof; @@ -294,3 +298,17 @@ fail: clear_header(out); return -1; } + +int skip_padding(istream_t *fp, sqfs_u64 size) +{ + size_t tail = size % 512; + + return tail ? istream_skip(fp, 512 - tail) : 0; +} + +int skip_entry(istream_t *fp, sqfs_u64 size) +{ + size_t tail = size % 512; + + return istream_skip(fp, tail ? (size + 512 - tail) : size); +} |