From ef64bc0803ca89212f5dcdec435325a294da4412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Tue, 21 May 2024 14:15:06 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4=E6=98=8E?= =?UTF-8?q?=20Modification=E3=80=91clean=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/src/ns.c | 8 ++++---- cli/src/options.c | 6 +++--- cli/src/u_mount.c | 8 ++++---- runtime/dcmi/dcmi_interface_api.h | 16 ++++++++-------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cli/src/ns.c b/cli/src/ns.c index 3f4fb3e..215389e 100644 --- a/cli/src/ns.c +++ b/cli/src/ns.c @@ -28,8 +28,8 @@ int GetNsPath(const long pid, const char *nsType, char *buf, const size_t bufSiz if ((nsType == NULL) || (buf == NULL)) { return -1; } - static const char *fmtStr = "/proc/%d/ns/%s"; - return sprintf_s(buf, bufSize, fmtStr, pid, nsType); + static const char *FMT_STR = "/proc/%d/ns/%s"; + return sprintf_s(buf, bufSize, FMT_STR, pid, nsType); } int GetSelfNsPath(const char *nsType, char *buf, const size_t bufSize) @@ -37,8 +37,8 @@ int GetSelfNsPath(const char *nsType, char *buf, const size_t bufSize) if ((nsType == NULL) || (buf == NULL)) { return -1; } - static const char *fmtStr = "/proc/self/ns/%s"; - return sprintf_s(buf, bufSize, fmtStr, nsType); + static const char *FMT_STR = "/proc/self/ns/%s"; + return sprintf_s(buf, bufSize, FMT_STR, nsType); } int EnterNsByFd(int fd, int nsType) diff --git a/cli/src/options.c b/cli/src/options.c index 4ea3f7d..5b75b32 100644 --- a/cli/src/options.c +++ b/cli/src/options.c @@ -43,7 +43,7 @@ void ParseRuntimeOptions(const char *options) g_runtimeOptions.noDrv = false; g_runtimeOptions.isVirtual = false; - static const char *seperator = ","; + static const char *SEPERATOR = ","; char *runtimeOptions = strdup(options); if (runtimeOptions == NULL) { (void)fprintf(stderr, "strdup failed!\n"); @@ -52,9 +52,9 @@ void ParseRuntimeOptions(const char *options) char *context = NULL; char *token = NULL; - for (token = strtok_s(runtimeOptions, seperator, &context); + for (token = strtok_s(runtimeOptions, SEPERATOR, &context); token != NULL; - token = strtok_s(NULL, seperator, &context)) { + token = strtok_s(NULL, SEPERATOR, &context)) { for (int i = 0; g_optionNameFlagTable[i].name != NULL; i++) { if (strcmp((const char *)token, g_optionNameFlagTable[i].name) == 0) { *g_optionNameFlagTable[i].flag = true; diff --git a/cli/src/u_mount.c b/cli/src/u_mount.c index 582f9f6..509d0e3 100644 --- a/cli/src/u_mount.c +++ b/cli/src/u_mount.c @@ -58,18 +58,18 @@ int Mount(const char *src, const char *dst) return -1; } - static const unsigned long mountFlags = MS_BIND; - static const unsigned long remountFlags = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NOSUID; + static const unsigned long MOUNT_FLAGS = MS_BIND; + static const unsigned long REMOUNT_FLAGS = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NOSUID; if (!CheckSrcFile(src)) { return -1; } - int ret = mount(src, dst, NULL, mountFlags, NULL); + int ret = mount(src, dst, NULL, MOUNT_FLAGS, NULL); if (ret < 0) { Logger("failed to mount src.", LEVEL_ERROR, SCREEN_YES); return -1; } - ret = mount(NULL, dst, NULL, remountFlags, NULL); + ret = mount(NULL, dst, NULL, REMOUNT_FLAGS, NULL); if (ret < 0) { Logger("failed to re-mount. dst.", LEVEL_ERROR, SCREEN_YES); return -1; diff --git a/runtime/dcmi/dcmi_interface_api.h b/runtime/dcmi/dcmi_interface_api.h index 78dba9f..ae5dcdd 100644 --- a/runtime/dcmi/dcmi_interface_api.h +++ b/runtime/dcmi/dcmi_interface_api.h @@ -84,14 +84,14 @@ int DcmiGetDeviceLogicId(int *deviceLogicId, int cardId, int deviceId) CALL_FUNC(g_dcmiGetDeviceLogicIdFunc, deviceLogicId, cardId, deviceId); } -int (*g_DcmiCreateVdeviceFunc)(int cardId, int deviceId, - struct DcmiCreateVdevResStru *vdev, - struct DcmiCreateVdevOut *out); +int (*g_dcmiCreateVdeviceFunc)(int cardId, int deviceId, + struct DcmiCreateVdevResStru *vdev, + struct DcmiCreateVdevOut *out); int DcmiCreateVdevice(int cardId, int deviceId, - struct DcmiCreateVdevResStru *vdev, - struct DcmiCreateVdevOut *out) + struct DcmiCreateVdevResStru *vdev, + struct DcmiCreateVdevOut *out) { - CALL_FUNC(g_DcmiCreateVdeviceFunc, cardId, deviceId, vdev, out); + CALL_FUNC(g_dcmiCreateVdeviceFunc, cardId, deviceId, vdev, out); } int (*g_dcmiSetDestroyVdeviceFunc)(int cardId, int deviceId, unsigned int vDevid); @@ -123,7 +123,7 @@ int DcmiInitDl(char *dlPath) { g_dcmiHandle = dlopen("libdcmi.so", RTLD_LAZY | RTLD_GLOBAL); if (g_dcmiHandle == NULL) { - fprintf (stderr, "%s\n", dlerror()); + fprintf(stderr, "%s\n", dlerror()); return SO_NOT_FOUND; } struct link_map *pLinkMap; @@ -146,7 +146,7 @@ int DcmiInitDl(char *dlPath) g_dcmiGetDeviceLogicIdFunc = dlsym(g_dcmiHandle, "dcmi_get_device_logic_id"); - g_DcmiCreateVdeviceFunc = dlsym(g_dcmiHandle, "dcmi_create_vdevice"); + g_dcmiCreateVdeviceFunc = dlsym(g_dcmiHandle, "dcmi_create_vdevice"); g_dcmiSetDestroyVdeviceFunc = dlsym(g_dcmiHandle, "dcmi_set_destroy_vdevice"); -- Gitee