Skip to contentSkip to conversation

device tree: simplify dumpdtb code

PATCH In review Alexander Graf 2 participants 2 messages Sep 25, 2012 – Oct 1, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 device tree: simplify dumpdtb code

As per Peter's suggestion, we can use glib to write out a buffer in whole to a file, simplifying the code dramatically.

---

This patch applies on top of the generic dumpdtb remodeling patch.

---
 device_tree.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)
device_tree.c +1 -8
index 69ca953..a923613 100644
@@ -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);
         }
     }
 
Signature · 1 line
1.6.0.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Alexander Graf

As per Peter's suggestion, we can use glib to write out a buffer in whole to a file, simplifying the code dramatically.

---

This patch applies on top of the generic dumpdtb remodeling patch.

---
 device_tree.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)
device_tree.c +0 -2
index 69ca953..a923613 100644
@@ -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;

device_tree.c void qemu_devtree_dumpdtb(void *fdt, int size) · line 320

Quoted 10 lines
device_tree.c +1 -6
-            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);
         }
     }
 
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net