diff options
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); +} |