tools: Add a function to obtain the size of a file
This will be used in mkimage when working out the required size of the FIT based on the files to be placed into it. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user