From 74bcd173609304917982f600ed3d757e1dd1092e Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Tue, 25 Feb 2020 21:25:29 +0800 Subject: [PATCH] in func writeToFile: change write to fc_safe_write --- HISTORY | 2 +- src/shared_func.c | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/HISTORY b/HISTORY index 60c9085..fccf998 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.44 2020-02-24 +Version 1.44 2020-02-25 * add test file src/tests/test_pthread_lock.c * add uniq_skiplist.[hc] * add function split_string_ex diff --git a/src/shared_func.c b/src/shared_func.c index 1480538..157b25c 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1079,16 +1080,12 @@ bool isFile(const char *filename) void chopPath(char *filePath) { int lastIndex; - if (*filePath == '\0') - { - return; - } lastIndex = strlen(filePath) - 1; - if (filePath[lastIndex] == '/') - { - filePath[lastIndex] = '\0'; - } + while (lastIndex >= 0 && filePath[lastIndex] == '/') + { + filePath[lastIndex--] = '\0'; + } } int getFileContent(const char *filename, char **buff, int64_t *file_size) @@ -1260,7 +1257,7 @@ int writeToFile(const char *filename, const char *buff, const int file_size) return result; } - if (write(fd, buff, file_size) != file_size) + if (fc_safe_write(fd, buff, file_size) != file_size) { result = errno != 0 ? errno : EIO; logError("file: "__FILE__", line: %d, " \ @@ -1291,7 +1288,7 @@ int writeToFile(const char *filename, const char *buff, const int file_size) int safeWriteToFile(const char *filename, const char *buff, \ const int file_size) { - char tmpFilename[MAX_PATH_SIZE]; + char tmpFilename[PATH_MAX]; int result; snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", filename);