]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/import/test-qcow2.c
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / import / test-qcow2.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright 2015 Lennart Poettering
4 ***/
5
6 #include "fd-util.h"
7 #include "log.h"
8 #include "qcow2-util.h"
9 #include "util.h"
10
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 }