summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-07 15:13:47 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-07 15:18:36 +0200
commit3ac100ddf7527882159665c97eed60fc442299de (patch)
treed078eb797c7828876044ea750c48ce9f4852fc6e
parentb04c5e0f9536d19b26efe1d69807c1f42b4b95ca (diff)
Replace write_data in libcommon with less generic, opencoded one
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/common/data_reader_dump.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/common/data_reader_dump.c b/lib/common/data_reader_dump.c
index 140f527..91b3141 100644
--- a/lib/common/data_reader_dump.c
+++ b/lib/common/data_reader_dump.c
@@ -11,6 +11,34 @@
#include <unistd.h>
#include <string.h>
#include <stdio.h>
+#include <errno.h>
+
+static int append_block(int fd, const sqfs_block_t *blk)
+{
+ const unsigned char *ptr = blk->data;
+ size_t size = blk->size;
+ ssize_t ret;
+
+ while (size > 0) {
+ ret = write(fd, ptr, size);
+
+ if (ret < 0) {
+ if (errno == EINTR)
+ continue;
+ perror("writing data block");
+ }
+
+ if (ret == 0) {
+ fputs("writing data block: unexpected end of file\n",
+ stderr);
+ }
+
+ ptr += ret;
+ size -= ret;
+ }
+
+ return 0;
+}
int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data,
const sqfs_inode_generic_t *inode,
@@ -46,8 +74,7 @@ int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data,
return -1;
}
- if (write_data("writing uncompressed block",
- outfd, blk->data, blk->size)) {
+ if (append_block(outfd, blk)) {
free(blk);
return -1;
}
@@ -64,8 +91,7 @@ int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data,
return -1;
}
- if (write_data("writing uncompressed fragment", outfd,
- blk->data, blk->size)) {
+ if (append_block(outfd, blk)) {
free(blk);
return -1;
}