summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2017-01-27 03:54:02 +0900
committerMasahiro Yamada <yamada.masahiro@socionext.com>2017-01-27 15:04:31 +0900
commita1da83f5fc91b15761fa418aedf14e155a7e24c6 (patch)
tree4901609ffb962a93722953ec7e6b4e017474ffa3 /tools
parent4f96a498436d63864de38b29ff2496755e16fb0c (diff)
fiptool: add xfwrite() helper
We have same patterns for fwrite(). Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/fiptool/fiptool.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/tools/fiptool/fiptool.c b/tools/fiptool/fiptool.c
index 0040018b..b02635f6 100644
--- a/tools/fiptool/fiptool.c
+++ b/tools/fiptool/fiptool.c
@@ -160,6 +160,12 @@ static void *xzalloc(size_t size, const char *msg)
return memset(xmalloc(size, msg), 0, size);
}
+static void xfwrite(void *buf, size_t size, FILE *fp, const char *filename)
+{
+ if (fwrite(buf, 1, size, fp) != size)
+ log_errx("Failed to write %s", filename);
+}
+
static image_desc_t *new_image_desc(const uuid_t *uuid,
const char *name, const char *cmdline_name)
{
@@ -497,8 +503,7 @@ static int write_image_to_file(const image_t *image, const char *filename)
fp = fopen(filename, "w");
if (fp == NULL)
log_err("fopen");
- if (fwrite(image->buffer, 1, image->size, fp) != image->size)
- log_errx("Failed to write %s", filename);
+ xfwrite(image->buffer, image->size, fp, filename);
fclose(fp);
return 0;
}
@@ -645,16 +650,14 @@ static int pack_images(const char *filename, uint64_t toc_flags)
if (verbose)
log_dbgx("Metadata size: %zu bytes", buf_size);
- if (fwrite(buf, 1, buf_size, fp) != buf_size)
- log_errx("Failed to write image to %s", filename);
+ xfwrite(buf, buf_size, fp, filename);
free(buf);
if (verbose)
log_dbgx("Payload size: %zu bytes", payload_size);
for (image = image_head; image != NULL; image = image->next)
- if (fwrite(image->buffer, 1, image->size, fp) != image->size)
- log_errx("Failed to write image to %s", filename);
+ xfwrite(image->buffer, image->size, fp, filename);
fclose(fp);
return 0;