fix return value checks of cbfstool's writerom
[coreboot.git] / util / cbfstool / common.c
index b071864b5c81923f9ed4772722e76976f7d2bc95..8478c5a492cc69005dc6acdc593db6fc9f4609ef 100644 (file)
@@ -90,11 +90,23 @@ void *loadrom(const char *filename)
        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)