imagetool: make the image_save_datafile() available to all image types

Move the image_save_datafile() function from an U-Multi specific file
(default_image.c) to a file common to all image types (image.c). And rename it
to genimg_save_datafile(), to make clear it is useful for any image type.

Signed-off-by: Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
This commit is contained in:
Guilherme Maciel Ferreira 2015-01-15 02:48:06 -02:00 committed by Tom Rini
parent 0ca6691c2e
commit 067d156075
4 changed files with 46 additions and 28 deletions

View file

@ -113,3 +113,30 @@ int imagetool_verify_print_header(
return retval;
}
int imagetool_save_datafile(
const char *file_name,
ulong file_data,
ulong file_len)
{
int dfd;
dfd = open(file_name, O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
S_IRUSR | S_IWUSR);
if (dfd < 0) {
fprintf(stderr, "Can't open \"%s\": %s\n",
file_name, strerror(errno));
return -1;
}
if (write(dfd, (void *)file_data, file_len) != (ssize_t)file_len) {
fprintf(stderr, "Write error on \"%s\": %s\n",
file_name, strerror(errno));
close(dfd);
return -1;
}
close(dfd);
return 0;
}