From 3afffc2a59cfc3888a84b2b2305b5312393ff4e8 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 6 Nov 2019 10:44:26 +0100 Subject: 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 --- difftool/extract.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'difftool') 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; } -- cgit v1.2.3