summaryrefslogtreecommitdiff
path: root/lib/tar/read_header.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-16 21:02:58 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-16 22:48:00 +0200
commite3ef871d6a80d72db02c9ab1ef492e8f58c2ddeb (patch)
treeec28b205b651e83c795e1e264aacfe5bcb307bc4 /lib/tar/read_header.c
parentbfd876dbf151df164b4d87de20aec39b24f205f9 (diff)
cleanup: move error handling into read_retry
If read_retry fails to read the expected amount of data (EOF or otherwise), it is almost always an error. This commit renames read_retry to read_data and moves error handling into the function, making a lot of error handling code redundant. 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.c30
1 files changed, 5 insertions, 25 deletions
diff --git a/lib/tar/read_header.c b/lib/tar/read_header.c
index 94c4a69..1769e0a 100644
--- a/lib/tar/read_header.c
+++ b/lib/tar/read_header.c
@@ -31,18 +31,12 @@ static int check_version(const tar_header_t *hdr)
static char *record_to_memory(int fd, uint64_t size)
{
char *buffer = malloc(size + 1);
- ssize_t ret;
if (buffer == NULL)
goto fail_errno;
- ret = read_retry(fd, buffer, size);
- if (ret == 0)
- goto fail_eof;
- if (ret < 0)
- goto fail_errno;
- if ((uint64_t)ret < size)
- goto fail_eof;
+ if (read_data("reading tar record", fd, buffer, size))
+ goto fail;
if (skip_padding(fd, size))
goto fail;
@@ -52,9 +46,6 @@ static char *record_to_memory(int fd, uint64_t size)
fail_errno:
perror("reading tar record");
goto fail;
-fail_eof:
- fputs("reading tar record: unexpected end of file\n", stderr);
- goto fail;
fail:
free(buffer);
return NULL;
@@ -416,18 +407,13 @@ int read_header(int fd, tar_header_decoded_t *out)
bool prev_was_zero = false;
uint64_t pax_size;
tar_header_t hdr;
- int ret, version;
+ int version;
memset(out, 0, sizeof(*out));
for (;;) {
- ret = read_retry(fd, &hdr, sizeof(hdr));
- if (ret == 0)
- goto out_eof;
- if (ret < 0)
- goto fail_errno;
- if (ret < (int)sizeof(hdr))
- goto fail_eof;
+ if (read_data("reading tar header", fd, &hdr, sizeof(hdr)))
+ goto fail;
if (is_zero_block(&hdr)) {
if (prev_was_zero)
@@ -499,12 +485,6 @@ int read_header(int fd, tar_header_decoded_t *out)
out_eof:
clear_header(out);
return 1;
-fail_errno:
- perror("reading tar header");
- goto fail;
-fail_eof:
- fputs("reading tar header: unexpected end of file\n", stderr);
- goto fail;
fail_magic:
fputs("input is not a ustar tar archive!\n", stderr);
goto fail;