diff --git a/HISTORY b/HISTORY index b415ee2..9d33a9b 100644 --- a/HISTORY +++ b/HISTORY @@ -4,6 +4,7 @@ Version 1.43 2019-12-25 system is the deprecated function in iOS 11 * correct function skiplist_iterator in skiplist.h * add buffered_file_writer.[hc] + * add function fc_delete_file_ex Version 1.42 2019-12-03 * add function get_gzip_command_filename diff --git a/src/shared_func.c b/src/shared_func.c index b2971eb..995edc3 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -2866,3 +2866,29 @@ const char *get_gzip_command_filename() return "gzip"; } } + +int fc_delete_file_ex(const char *filename, const char *caption) +{ + int result; + + if (unlink(filename) == 0) + { + return 0; + } + + result = errno != 0 ? errno : ENOENT; + if (result == ENOENT) + { + result = 0; + } + else + { + logError("file: "__FILE__", line: %d, " + "unlink %s file: %s fail, " + "errno: %d, error info: %s", + __LINE__, caption, filename, + result, STRERROR(result)); + } + + return result; +} diff --git a/src/shared_func.h b/src/shared_func.h index 0ed530c..2ffc2fa 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -856,6 +856,19 @@ char *resolve_path(const char *from, const char *filename, */ const char *get_gzip_command_filename(); +/** delete file + * parameters: + * filename: the filename to delete + * caption: the caption of this filename + * return: error no, 0 success, != 0 fail +*/ +int fc_delete_file_ex(const char *filename, const char *caption); + +static inline int fc_delete_file(const char *filename) +{ + return fc_delete_file_ex(filename, ""); +} + #ifdef __cplusplus } #endif