From 067d15607598884e270f3076c721f56d3c4f65e6 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Thu, 15 Jan 2015 02:48:06 -0200 Subject: 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 --- tools/imagetool.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tools/imagetool.c') diff --git a/tools/imagetool.c b/tools/imagetool.c index e4de7af..a25b86b 100644 --- a/tools/imagetool.c +++ b/tools/imagetool.c @@ -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; +} -- cgit v1.1