From 100fd4323371a3be8e936e54f06dbc3ec4e14cee Mon Sep 17 00:00:00 2001 From: armink Date: Sat, 27 Jun 2020 11:16:54 +0800 Subject: [PATCH] [plugin][file] remove the access function using. --- easylogger/plugins/file/elog_file.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/easylogger/plugins/file/elog_file.c b/easylogger/plugins/file/elog_file.c index 27b197e..e990db8 100644 --- a/easylogger/plugins/file/elog_file.c +++ b/easylogger/plugins/file/elog_file.c @@ -26,8 +26,9 @@ * Created on: 2019-01-05 */ + #define LOG_TAG "elog.file" + #include -#include #include #include #include @@ -71,6 +72,7 @@ static bool elog_file_rotate(void) char oldpath[256], newpath[256]; size_t base = strlen(local_cfg.name); bool result = true; + FILE *tmp_fp; memcpy(oldpath, local_cfg.name, base); memcpy(newpath, local_cfg.name, base); @@ -81,11 +83,13 @@ static bool elog_file_rotate(void) snprintf(oldpath + base, SUFFIX_LEN, n ? ".%d" : "", n - 1); snprintf(newpath + base, SUFFIX_LEN, ".%d", n); /* remove the old file */ - if (access(newpath, F_OK) == 0) { + if ((tmp_fp = fopen(newpath , "r")) != NULL) { + fclose(tmp_fp); remove(newpath); } /* change the new log file to old file name */ - if (access(oldpath, F_OK) == 0) { + if ((tmp_fp = fopen(oldpath , "r")) != NULL) { + fclose(tmp_fp); err = rename(oldpath, newpath); }