From patchwork Thu Oct 4 13:56:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [30/34] device tree: simplify dumpdtb code Date: Thu, 04 Oct 2012 03:56:52 -0000 From: Alexander Graf X-Patchwork-Id: 189188 Message-Id: <1349359016-13107-31-git-send-email-agraf@suse.de> To: qemu-devel qemu-devel Cc: Blue Swirl , "qemu-ppc@nongnu.org List" , Aurelien Jarno 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 --- device_tree.c | 9 +-------- 1 files changed, 1 insertions(+), 8 deletions(-) diff --git a/device_tree.c b/device_tree.c index 69ca953..a923613 100644 --- a/device_tree.c +++ b/device_tree.c @@ -314,14 +314,7 @@ void qemu_devtree_dumpdtb(void *fdt, int size) 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); } }