As per Peter's suggestion, we can use glib to write out a buffer in whole to
a file, simplifying the code dramatically.
Signed-off-by: Alexander Graf <agraf@suse.de>
const char *dumpdtb = qemu_opt_get(machine_opts, "dumpdtb");
if (dumpdtb) {
/* Dump the dtb to a file and quit */
- FILE *f = fopen(dumpdtb, "wb");
- size_t len;
- len = fwrite(fdt, size, 1, f);
- fclose(f);
- if (len != size) {
- exit(1);
- }
- exit(0);
+ exit(g_file_set_contents(dumpdtb, fdt, size, NULL) ? 0 : 1);
}
}