]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/import/test-qcow2.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / import / test-qcow2.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
edce2aed
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2015 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
3ffd4af2 21#include "fd-util.h"
edce2aed 22#include "log.h"
edce2aed 23#include "qcow2-util.h"
3ffd4af2 24#include "util.h"
edce2aed
LP
25
26int main(int argc, char *argv[]) {
27 _cleanup_close_ int sfd = -1, dfd = -1;
28 int r;
29
30 if (argc != 3) {
31 log_error("Needs two arguments.");
32 return EXIT_FAILURE;
33 }
34
35 sfd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY);
36 if (sfd < 0) {
37 log_error_errno(errno, "Can't open source file: %m");
38 return EXIT_FAILURE;
39 }
40
41 dfd = open(argv[2], O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0666);
42 if (dfd < 0) {
43 log_error_errno(errno, "Can't open destination file: %m");
44 return EXIT_FAILURE;
45 }
46
47 r = qcow2_convert(sfd, dfd);
48 if (r < 0) {
49 log_error_errno(r, "Failed to unpack: %m");
50 return EXIT_FAILURE;
51 }
52
53 return EXIT_SUCCESS;
54}