summaryrefslogtreecommitdiff
path: root/difftool/extract.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-06 10:44:26 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-06 11:10:58 +0100
commit3afffc2a59cfc3888a84b2b2305b5312393ff4e8 (patch)
tree029ac4c5f55e9e7149cd40d0f57c52efcd41608f /difftool/extract.c
parent9f1f3f959d3411c200afb5a1df4fffa9d87df616 (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 'difftool/extract.c')
-rw-r--r--difftool/extract.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/difftool/extract.c b/difftool/extract.c
index df00977..979572a 100644
--- a/difftool/extract.c
+++ b/difftool/extract.c
@@ -10,7 +10,7 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode,
const char *prefix, const char *path, size_t block_size)
{
char *ptr, *temp;
- int fd;
+ FILE *fp;
temp = alloca(strlen(prefix) + strlen(path) + 2);
sprintf(temp, "%s/%s", prefix, path);
@@ -21,18 +21,19 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode,
return -1;
*ptr = '/';
- fd = open(temp, O_CREAT | O_EXCL | O_WRONLY, 0600);
- if (fd < 0) {
+ fp = fopen(temp, "wb");
+ if (fp == NULL) {
perror(temp);
return -1;
}
- if (sqfs_data_reader_dump(path, data, inode, fd, block_size, true)) {
- close(fd);
+ if (sqfs_data_reader_dump(path, data, inode, fp, block_size, true)) {
+ fclose(fp);
return -1;
}
- close(fd);
+ fflush(fp);
+ fclose(fp);
return 0;
}