diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-06 10:44:26 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-06 11:10:58 +0100 |
commit | 3afffc2a59cfc3888a84b2b2305b5312393ff4e8 (patch) | |
tree | 029ac4c5f55e9e7149cd40d0f57c52efcd41608f /unpack/fill_files.c | |
parent | 9f1f3f959d3411c200afb5a1df4fffa9d87df616 (diff) |
Remove raw file descriptors from unpack write paths
Instead, use stdio FILE pointers. On POSIX systems, use fileno to get
the file descriptor and hopefully create sparase files.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'unpack/fill_files.c')
-rw-r--r-- | unpack/fill_files.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/unpack/fill_files.c b/unpack/fill_files.c index e6444b2..d22e9d1 100644 --- a/unpack/fill_files.c +++ b/unpack/fill_files.c @@ -136,11 +136,11 @@ static int gen_file_list_dfs(const sqfs_tree_node_t *n) static int fill_files(sqfs_data_reader_t *data, int flags) { size_t i; - int fd; + FILE *fp; for (i = 0; i < num_files; ++i) { - fd = open(files[i].path, O_WRONLY); - if (fd < 0) { + fp = fopen(files[i].path, "wb"); + if (fp == NULL) { fprintf(stderr, "unpacking %s: %s\n", files[i].path, strerror(errno)); return -1; @@ -150,13 +150,14 @@ static int fill_files(sqfs_data_reader_t *data, int flags) printf("unpacking %s\n", files[i].path); if (sqfs_data_reader_dump(files[i].path, data, files[i].inode, - fd, block_size, + fp, block_size, (flags & UNPACK_NO_SPARSE) == 0)) { - close(fd); + fclose(fp); return -1; } - close(fd); + fflush(fp); + fclose(fp); } return 0; |