mirror of https://github.com/thesofproject/sof.git
file_utils: Add file_error function
Added a generic function that displays a file operation error message. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
This commit is contained in:
parent
dd15443129
commit
32a5388c10
|
@ -8,9 +8,21 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <rimage/file_utils.h>
|
#include <rimage/file_utils.h>
|
||||||
|
|
||||||
|
int file_error(const char *msg, const char *filename)
|
||||||
|
{
|
||||||
|
int code = errno;
|
||||||
|
char sys_msg[256];
|
||||||
|
|
||||||
|
strerror_r(code, sys_msg, sizeof(sys_msg));
|
||||||
|
|
||||||
|
fprintf(stderr, "%s:\terror: %s. %s (errno = %d)\n", filename, msg, sys_msg, code);
|
||||||
|
return -code;
|
||||||
|
}
|
||||||
|
|
||||||
int create_file_name(char *new_name, const size_t name_size, const char *template_name,
|
int create_file_name(char *new_name, const size_t name_size, const char *template_name,
|
||||||
const char *new_ext)
|
const char *new_ext)
|
||||||
{
|
{
|
||||||
|
@ -37,22 +49,16 @@ int get_file_size(FILE *f, const char* filename, size_t *size)
|
||||||
|
|
||||||
/* get file size */
|
/* get file size */
|
||||||
ret = fseek(f, 0, SEEK_END);
|
ret = fseek(f, 0, SEEK_END);
|
||||||
if (ret < 0) {
|
if (ret)
|
||||||
fprintf(stderr, "error: unable to seek eof %s %d\n", filename, errno);
|
return file_error("unable to seek eof", filename);
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
*size = ftell(f);
|
*size = ftell(f);
|
||||||
if (*size < 0) {
|
if (*size < 0)
|
||||||
fprintf(stderr, "error: unable to get file size for %s %d\n", filename, errno);
|
return file_error("unable to get file size", filename);
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = fseek(f, 0, SEEK_SET);
|
ret = fseek(f, 0, SEEK_SET);
|
||||||
if (ret < 0) {
|
if (ret)
|
||||||
fprintf(stderr, "error: unable to seek set %s %d\n", filename, errno);
|
return file_error("unable to seek set", filename);
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,14 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print file operation error message
|
||||||
|
* @param [in]msg error message
|
||||||
|
* @param [in]filename File name used to display the error message
|
||||||
|
* @param error code
|
||||||
|
*/
|
||||||
|
int file_error(const char *msg, const char *filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new file name using output file name as template.
|
* Create new file name using output file name as template.
|
||||||
* @param [out] new_name char[] destination of new file name
|
* @param [out] new_name char[] destination of new file name
|
||||||
|
|
Loading…
Reference in New Issue