Author: stepan
Date: Thu Jun 24 15:37:59 2010
New Revision: 5644
URL: https://tracker.coreboot.org/trac/coreboot/changeset/5644

Log:
fix return value checks of cbfstool's writerom
Signed-off-by: Stefan Reinauer <[email protected]>
Acked-by: Stefan Reinauer <[email protected]>

Modified:
   trunk/util/cbfstool/cbfstool.c
   trunk/util/cbfstool/common.c
   trunk/util/cbfstool/common.h

Modified: trunk/util/cbfstool/cbfstool.c
==============================================================================
--- trunk/util/cbfstool/cbfstool.c      Thu Jun 24 13:16:10 2010        (r5643)
+++ trunk/util/cbfstool/cbfstool.c      Thu Jun 24 15:37:59 2010        (r5644)
@@ -83,7 +83,8 @@
        cbfsfile = create_cbfs_file(cbfsname, filedata, &filesize, type, &base);
        if (add_file_to_cbfs(cbfsfile, filesize, base))
                return 1;
-       writerom(romname, rom, romsize);
+       if (writerom(romname, rom, romsize))
+               return 1;
        return 0;
 }
 
@@ -131,7 +132,8 @@
                             CBFS_COMPONENT_PAYLOAD, &base);
        if (add_file_to_cbfs(cbfsfile, filesize, base))
                return 1;
-       writerom(romname, rom, romsize);
+       if (writerom(romname, rom, romsize))
+               return 1;
        return 0;
 }
 
@@ -180,7 +182,8 @@
 
        if (add_file_to_cbfs(cbfsfile, filesize, base))
                return 1;
-       writerom(romname, rom, romsize);
+       if (writerom(romname, rom, romsize))
+               return 1;
        return 0;
 }
 

Modified: trunk/util/cbfstool/common.c
==============================================================================
--- trunk/util/cbfstool/common.c        Thu Jun 24 13:16:10 2010        (r5643)
+++ trunk/util/cbfstool/common.c        Thu Jun 24 15:37:59 2010        (r5644)
@@ -90,11 +90,23 @@
        return romarea;
 }
 
-void writerom(const char *filename, void *start, uint32_t size)
+int writerom(const char *filename, void *start, uint32_t size)
 {
        FILE *file = fopen(filename, "wb");
-       fwrite(start, size, 1, file);
+       if (!file) {
+               fprintf(stderr, "Could not open '%s' for writing: ", filename);
+               perror("");
+               return 1;
+       }
+
+       if (fwrite(start, size, 1, file) != 1) {
+               fprintf(stderr, "Could not write to '%s': ", filename);
+               perror("");
+               return 1;
+       }
+
        fclose(file);
+       return 0;
 }
 
 int cbfs_file_header(uint32_t physaddr)

Modified: trunk/util/cbfstool/common.h
==============================================================================
--- trunk/util/cbfstool/common.h        Thu Jun 24 13:16:10 2010        (r5643)
+++ trunk/util/cbfstool/common.h        Thu Jun 24 15:37:59 2010        (r5644)
@@ -44,7 +44,7 @@
 void *loadfile(const char *filename, uint32_t * romsize_p, void *content,
               int place);
 void *loadrom(const char *filename);
-void writerom(const char *filename, void *start, uint32_t size);
+int writerom(const char *filename, void *start, uint32_t size);
 
 int iself(unsigned char *input);
 

-- 
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to