From 9ae19d365899f62b0ce35cec4eab700957ce2fe5 Mon Sep 17 00:00:00 2001 From: zhaohang Date: Thu, 19 Sep 2024 16:50:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=B6=85=E9=95=BF=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaohang --- include/context_tool.h | 1 + src/context_tool.c | 13 +++++++++++++ src/create_pcid.c | 24 +++--------------------- src/syscap_tool.c | 8 +------- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/include/context_tool.h b/include/context_tool.h index b8b437a..2160be7 100644 --- a/include/context_tool.h +++ b/include/context_tool.h @@ -40,6 +40,7 @@ typedef struct RequiredProductCompatibilityIDHead { void FreeContextBuffer(char *contextBuffer); int32_t GetFileContext(const char *inputFile, char **contextBufPtr, uint32_t *bufferLen); +int32_t CheckFileAndGetFileContext(const char *inputFile, char **contextBufPtr, uint32_t *bufferLen); int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename, char *convertedBuffer, size_t contextBufLen); int32_t CheckRpcidFormat(const char *inputFile, char **buffer, uint32_t *len); cJSON *CreateWholeSyscapJsonObj(void); diff --git a/src/context_tool.c b/src/context_tool.c index ea5359f..e75f853 100644 --- a/src/context_tool.c +++ b/src/context_tool.c @@ -92,6 +92,19 @@ int32_t GetFileContext(const char *inputFile, char **contextBufPtr, uint32_t *bu return 0; } +int32_t CheckFileAndGetFileContext(const char *inputFile, char **contextBufPtr, uint32_t *bufferLen) +{ + if (inputFile == NULL) { + PRINT_ERR("input file is NULL.\n"); + return -1; + } + uint32_t ret = GetFileContext(inputFile, contextBufPtr, bufferLen); + if (ret != 0) { + PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); + } + return ret; +} + int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename, char *convertedBuffer, size_t contextBufLen) { int32_t ret; diff --git a/src/create_pcid.c b/src/create_pcid.c index ba4b838..5a8a327 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -250,15 +250,9 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) uint32_t contextBufLen; char *contextBuffer = NULL; - if (inputFile == NULL) { - PRINT_ERR("inputFile is null.\n"); - return -1; - } - cJSON *allOsSyscapObj = CreateWholeSyscapJsonObj(); - int32_t ret = GetFileContext(inputFile, &contextBuffer, (uint32_t *)&contextBufLen); + int32_t ret = CheckFileAndGetFileContext(inputFile, &contextBuffer, (uint32_t *)&contextBufLen); if (ret != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, -1); } @@ -486,15 +480,9 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) freePcidJsonInfo.jsonRootObj = NULL; freePcidJsonInfo.sysCapObj = NULL; freePcidJsonInfo.flag = 0; - - if (inputFile == NULL) { - PRINT_ERR("inputFile is null.\n"); - return -1; - } - ret = GetFileContext(inputFile, &freePcidJsonInfo.contextBuffer, (uint32_t *)&contextBufLen); + ret = CheckFileAndGetFileContext(inputFile, &freePcidJsonInfo.contextBuffer, (uint32_t *)&contextBufLen); if (ret != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); return -1; } @@ -887,14 +875,8 @@ int32_t EncodePcidscToString(char *inputFile, char *outDirPath) freePcidInfo.outDirPathFinal = outDirPath; PCIDMain *pcidMain = NULL; - if (inputFile == NULL) { - PRINT_ERR("inputFile is null.\n"); - return -1; - } - - ret = GetFileContext(inputFile, &freePcidInfo.contextBuffer, (uint32_t *)&bufferLen); + ret = CheckFileAndGetFileContext(inputFile, &freePcidInfo.contextBuffer, (uint32_t *)&bufferLen); if (ret != 0) { - PRINT_ERR("Get pcid file failed, pcid file path: %s\n", inputFile); return -1; } diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 2b08974..d58259b 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -150,13 +150,7 @@ int32_t RPCIDEncode(char *inputFile, char *outputPath) gJsonObjectSysCap.cjsonObjectRoot = NULL; gJsonObjectSysCap.sysCapPtr = NULL; - if (inputFile == NULL) { - PRINT_ERR("inputFile is null.\n"); - return -1; - } - - if (GetFileContext(inputFile, &contextBuffer, &bufferLen) != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); + if (CheckFileAndGetFileContext(inputFile, &contextBuffer, &bufferLen) != 0) { return -1; }