From 8ececbef93744dd7ea9e306b89d96f488ffc6c42 Mon Sep 17 00:00:00 2001 From: Gymee <8039110+Gymee@user.noreply.gitee.com> Date: Fri, 25 Sep 2020 23:59:29 +0800 Subject: [PATCH] simplify code by replace strncmp with strcmp --- src/init_cmds.c | 10 +++++----- src/init_service_manager.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/init_cmds.c b/src/init_cmds.c index 90b9c2119..79cbed108 100755 --- a/src/init_cmds.c +++ b/src/init_cmds.c @@ -313,15 +313,15 @@ void DoCmd(const CmdLine* curCmd) return; } - if (strncmp(curCmd->name, "start ", strlen("start ")) == 0) { + if (strcmp(curCmd->name, "start ") == 0) { DoStart(curCmd->cmdContent); - } else if (strncmp(curCmd->name, "mkdir ", strlen("mkdir ")) == 0) { + } else if (strcmp(curCmd->name, "mkdir ") == 0) { DoMkDir(curCmd->cmdContent); - } else if (strncmp(curCmd->name, "chmod ", strlen("chmod ")) == 0) { + } else if (strcmp(curCmd->name, "chmod ") == 0) { DoChmod(curCmd->cmdContent); - } else if (strncmp(curCmd->name, "chown ", strlen("chown ")) == 0) { + } else if (strcmp(curCmd->name, "chown ") == 0) { DoChown(curCmd->cmdContent); - } else if (strncmp(curCmd->name, "mount ", strlen("mount ")) == 0) { + } else if (strcmp(curCmd->name, "mount ") == 0) { DoMount(curCmd->cmdContent); } else { printf("[Init] DoCmd, unknown cmd name %s.\n", curCmd->name); diff --git a/src/init_service_manager.c b/src/init_service_manager.c index fa8dc9e84..290bd10a9 100755 --- a/src/init_service_manager.c +++ b/src/init_service_manager.c @@ -42,7 +42,7 @@ static int FindServiceByName(const char* servName) for (int i = 0; i < g_servicesCnt; ++i) { if (strlen(g_services[i].name) == strlen(servName) && - strncmp(g_services[i].name, servName, strlen(g_services[i].name)) == 0) { + strcmp(g_services[i].name, servName) == 0) { return i; } } -- Gitee