summaryrefslogtreecommitdiff
path: root/ext4_utils/ext2simg.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext4_utils/ext2simg.c')
-rw-r--r--ext4_utils/ext2simg.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/ext4_utils/ext2simg.c b/ext4_utils/ext2simg.c
index 9332bada..d5fc24ff 100644
--- a/ext4_utils/ext2simg.c
+++ b/ext4_utils/ext2simg.c
@@ -169,7 +169,7 @@ int main(int argc, char **argv)
const char *out = NULL;
int gzip = 0;
int sparse = 1;
- int fd;
+ int infd, outfd;
int crc = 0;
while ((opt = getopt(argc, argv, "cvzS")) != -1) {
@@ -211,18 +211,29 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
- fd = open(in, O_RDONLY);
+ infd = open(in, O_RDONLY);
- if (fd < 0)
+ if (infd < 0)
critical_error_errno("failed to open input image");
- read_ext(fd);
+ read_ext(infd);
- build_sparse_ext(fd, in);
+ build_sparse_ext(infd, in);
- close(fd);
+ close(infd);
- write_ext4_image(out, gzip, sparse, crc, 0);
+ if (strcmp(out, "-")) {
+ outfd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (outfd < 0) {
+ error_errno("open");
+ return EXIT_FAILURE;
+ }
+ } else {
+ outfd = STDOUT_FILENO;
+ }
+
+ write_ext4_image(outfd, gzip, sparse, crc, 0);
+ close(outfd);
return 0;
}