Patchwork device tree: simplify dumpdtb code

login
register
mail settings
Submitter Alexander Graf
Date Sept. 23, 2012, 9:29 p.m.
Message ID <1348435772-26553-1-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/186700/
State New
Headers show

Comments

Alexander Graf - Sept. 23, 2012, 9:29 p.m.
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>

---

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

---
 device_tree.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)
Aurelien Jarno - Oct. 1, 2012, 7:15 p.m.
On Sun, Sep 23, 2012 at 11:29:32PM +0200, Alexander Graf wrote:
> 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>
> 
> ---
> 
> This patch applies on top of the generic dumpdtb remodeling patch.
> 
> ---
>  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);
>          }
>      }
>  

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>

Patch

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);
         }
     }