aboutsummaryrefslogtreecommitdiff
blob: a7977bb81a3a2f96c6fc1ee8aff03e54e59bf494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <config.h>

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "conf.h"

int main(int argc, char **argv) {
    int ret;
    virConfPtr conf;
    int len = 10000;
    char buffer[10000];

    if (argc != 2) {
        fprintf(stderr, "Usage: %s conf_file\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    conf = virConfReadFile(argv[1], 0);
    if (conf == NULL) {
        fprintf(stderr, "Failed to process %s\n", argv[1]);
        exit(EXIT_FAILURE);
    }
    ret = virConfWriteMem(&buffer[0], &len, conf);
    if (ret < 0) {
        fprintf(stderr, "Failed to serialize %s back\n", argv[1]);
        exit(EXIT_FAILURE);
    }
    virConfFree(conf);
    if (fwrite(buffer, 1, len, stdout) != len) {
        fprintf(stderr, "Write failed: %s\n", strerror (errno));
        exit(EXIT_FAILURE);
    }
    exit(EXIT_SUCCESS);
}