diff --git a/service/hnp/base/hnp_file.c b/service/hnp/base/hnp_file.c index e7a752b8..1995d645 100644 --- a/service/hnp/base/hnp_file.c +++ b/service/hnp/base/hnp_file.c @@ -124,6 +124,7 @@ int GetRealPath(char *srcPath, char *realPath) return HNP_ERRNO_PARAM_INVALID; } #ifdef _WIN32 + // 使用wchar_t支持处理字符串长度超过260的路径字符串 wchar_t wideSrcPath[MAX_FILE_PATH_LEN] = {0}; wchar_t wideDstPathExt[MAX_FILE_PATH_LEN] = {0}; MultiByteToWideChar(CP_ACP, 0, srcPath, -1, wideSrcPath, MAX_FILE_PATH_LEN); diff --git a/service/hnp/base/hnp_zip.c b/service/hnp/base/hnp_zip.c index 63e082bd..bc9a17ab 100644 --- a/service/hnp/base/hnp_zip.c +++ b/service/hnp/base/hnp_zip.c @@ -55,6 +55,7 @@ static void TransPath(const char *input, char *output) } #ifdef _WIN32 +// 转换char路径字符串为wchar_t宽字符串,支持路径字符串长度超过260 static bool TransWidePath(const char *inPath, wchar_t *outPath) { wchar_t tmpPath[MAX_FILE_PATH_LEN] = {0}; @@ -79,6 +80,7 @@ static int ZipAddFile(const char* file, int offset, zipFile zf) #ifdef _WIN32 struct _stat buffer = {0}; + // 使用wchar_t支持处理字符串长度超过260的路径字符串 wchar_t wideFullPath[MAX_FILE_PATH_LEN] = {0}; if (!TransWidePath(file, wideFullPath)) { return HNP_ERRNO_BASE_STAT_FAILED; @@ -125,10 +127,11 @@ static int ZipAddFile(const char* file, int offset, zipFile zf) static int IsDirPath(struct dirent *entry, char *fullPath, int *isDir) { #ifdef _WIN32 + // 使用wchar_t支持处理字符串长度超过260的路径字符串 wchar_t wideFullPath[MAX_FILE_PATH_LEN] = {0}; if (!TransWidePath(fullPath, wideFullPath)) { return HNP_ERRNO_GET_FILE_ATTR_FAILED; - } + } DWORD fileAttr = GetFileAttributesW(wideFullPath); if (fileAttr == INVALID_FILE_ATTRIBUTES) { DWORD err = GetLastError(); @@ -182,7 +185,7 @@ static int ZipAddDir(const char *sourcePath, int offset, zipFile zf) if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { continue; } - if (sprintf_s(fullPath, MAX_FILE_PATH_LEN, "%s%c%s", sourcePath, entry->d_name) < 0) { + if (sprintf_s(fullPath, MAX_FILE_PATH_LEN, "%s%s", sourcePath, entry->d_name) < 0) { HNP_LOGE("sprintf unsuccess."); closedir(dir); return HNP_ERRNO_BASE_SPRINTF_FAILED; diff --git a/service/hnp/pack/src/hnp_pack.c b/service/hnp/pack/src/hnp_pack.c index 39705a73..3b75bc0f 100644 --- a/service/hnp/pack/src/hnp_pack.c +++ b/service/hnp/pack/src/hnp_pack.c @@ -119,7 +119,7 @@ static int GetHnpCfgInfo(const char *hnpCfgPath, const char *sourcePath, HnpCfgI /* 校验软连接的source文件是否存在 */ linkArr = hnpCfg->links; for (unsigned int i = 0; i < hnpCfg->linkNum; i++, linkArr++) { - ret = sprintf_s(linksource, MAX_FILE_PATH_LEN, "%s%c%s", sourcePath, DIR_SPLIT_SYMBOL, linkArr->source); + ret = sprintf_s(linksource, MAX_FILE_PATH_LEN, "%s/%s", sourcePath, linkArr->source); if (ret < 0) { free(hnpCfg->links); hnpCfg->links = NULL;