summaryrefslogtreecommitdiff
path: root/tools/imagetool.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/imagetool.c')
-rw-r--r--tools/imagetool.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/imagetool.c b/tools/imagetool.c
index 4b0b73db52..351211cd53 100644
--- a/tools/imagetool.c
+++ b/tools/imagetool.c
@@ -91,3 +91,25 @@ int imagetool_save_subimage(
return 0;
}
+
+int imagetool_get_filesize(struct image_tool_params *params, const char *fname)
+{
+ struct stat sbuf;
+ int fd;
+
+ fd = open(fname, O_RDONLY | O_BINARY);
+ if (fd < 0) {
+ fprintf(stderr, "%s: Can't open %s: %s\n",
+ params->cmdname, fname, strerror(errno));
+ return -1;
+ }
+
+ if (fstat(fd, &sbuf) < 0) {
+ fprintf(stderr, "%s: Can't stat %s: %s\n",
+ params->cmdname, fname, strerror(errno));
+ return -1;
+ }
+ close(fd);
+
+ return sbuf.st_size;
+}