aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/data_writer.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/sqfs/data_writer.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/sqfs/data_writer.c')
-rw-r--r--lib/sqfs/data_writer.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/lib/sqfs/data_writer.c b/lib/sqfs/data_writer.c
index eebd2a4..64e27fa 100644
--- a/lib/sqfs/data_writer.c
+++ b/lib/sqfs/data_writer.c
@@ -160,7 +160,6 @@ int write_data_from_fd(data_writer_t *data, file_info_t *fi,
int infd, int flags)
{
uint64_t count;
- ssize_t ret;
size_t diff;
if ((flags & DW_ALLIGN_DEVBLK) && allign_file(data) != 0)
@@ -174,11 +173,8 @@ int write_data_from_fd(data_writer_t *data, file_info_t *fi,
diff = count > (uint64_t)data->super->block_size ?
data->super->block_size : count;
- ret = read_retry(infd, data->block, diff);
- if (ret < 0)
- goto fail_read;
- if ((size_t)ret < diff)
- goto fail_trunc;
+ if (read_data(fi->input_file, infd, data->block, diff))
+ return -1;
if (flush_data_block(data, diff, fi, flags))
return -1;
@@ -188,12 +184,6 @@ int write_data_from_fd(data_writer_t *data, file_info_t *fi,
return -1;
return 0;
-fail_read:
- perror(fi->input_file);
- return -1;
-fail_trunc:
- fprintf(stderr, "%s: truncated read\n", fi->input_file);
- return -1;
}
int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi,
@@ -202,7 +192,6 @@ int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi,
size_t start, count, diff;
sparse_map_t *m;
uint64_t offset;
- ssize_t ret;
if ((flags & DW_ALLIGN_DEVBLK) && allign_file(data) != 0)
return -1;
@@ -246,12 +235,10 @@ int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi,
if (start + count > diff)
count = diff - start;
- ret = read_retry(infd, (char *)data->block + start,
- count);
- if (ret < 0)
- goto fail_read;
- if ((size_t)ret < count)
- goto fail_trunc;
+ if (read_data(fi->input_file, infd,
+ (char *)data->block + start, count)) {
+ return -1;
+ }
map = map->next;
}
@@ -273,12 +260,6 @@ fail_map:
"%s: sparse file map is unordered or self overlapping\n",
fi->input_file);
return -1;
-fail_read:
- perror(fi->input_file);
- return -1;
-fail_trunc:
- fprintf(stderr, "%s: truncated read\n", fi->input_file);
- return -1;
}
data_writer_t *data_writer_create(sqfs_super_t *super, compressor_t *cmp,