From dfc8e06836fa316a99fd16aa06b5459456204bfc Mon Sep 17 00:00:00 2001 From: lichao Date: Tue, 23 Apr 2024 15:40:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=A7=84=E8=8C=83=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lichao --- src/create_pcid.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/create_pcid.c b/src/create_pcid.c index 7ada1bf..50e7844 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -687,24 +687,32 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt return 0; } +int32_t GetSyscapStr(char *input, char const *priSyscapStr, uint32_t* osSyscap, uint32_t *pcidHeader) { + char *ctx = NULL; + uint32_t fileContextLen; + if (GetFileContext(input, &ctx, (uint32_t *)&fileContextLen) != 0) { + PRINT_ERR("GetFileContext failed, input file : %s\n", input); + return -1; + } + if (ParseStringSyscap(ctx, osSyscap, OS_SYSCAP_NUM, pcidHeader, PCID_HEADER) != 0) { + PRINT_ERR("Parse string syscap failed.\n"); + return -1; + } + priSyscapStr = ctx; + free(ctx); + return 0; +} + int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) { int32_t ret = -1; uint32_t osSyscap[OS_SYSCAP_NUM] = {0}; uint32_t pcidHeader[PCID_HEADER]; - uint32_t fileContextLen; - char *ctx = NULL; char *priSyscapStr = NULL; - - if (GetFileContext(input, &ctx, (uint32_t *)&fileContextLen) != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", input); - goto PARSE_FAILED; + ret = GetSyscapStr(input, priSyscapStr, osSyscap, pcidHeader); + if (ret == -1) { + return ret; } - if (ParseStringSyscap(ctx, osSyscap, OS_SYSCAP_NUM, pcidHeader, PCID_HEADER) != 0) { - PRINT_ERR("Parse string syscap failed.\n"); - goto PARSE_FAILED; - } - priSyscapStr = ctx; // add to json object cJSON *sysCapObj = cJSON_CreateObject(); @@ -740,8 +748,6 @@ SAVE_FAILED: ADD_JSON_FAILED: cJSON_Delete(sysCapObj); cJSON_Delete(rootObj); -PARSE_FAILED: - free(ctx); return ret; }