1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include <fcntl.h>
4 #include <sys/stat.h>
5 #include <sys/types.h>
6 
7 #include "fd-util.h"
8 #include "log.h"
9 #include "qcow2-util.h"
10 
main(int argc,char * argv[])11 int main(int argc, char *argv[]) {
12         _cleanup_close_ int sfd = -1, dfd = -1;
13         int r;
14 
15         if (argc != 3) {
16                 log_error("Needs two arguments.");
17                 return EXIT_FAILURE;
18         }
19 
20         sfd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY);
21         if (sfd < 0) {
22                 log_error_errno(errno, "Can't open source file: %m");
23                 return EXIT_FAILURE;
24         }
25 
26         dfd = open(argv[2], O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0666);
27         if (dfd < 0) {
28                 log_error_errno(errno, "Can't open destination file: %m");
29                 return EXIT_FAILURE;
30         }
31 
32         r = qcow2_convert(sfd, dfd);
33         if (r < 0) {
34                 log_error_errno(r, "Failed to unpack: %m");
35                 return EXIT_FAILURE;
36         }
37 
38         return EXIT_SUCCESS;
39 }
40