提交 bc9685c1 编写于 作者: Z zhong_ning

init : fix code style

Signed-off-by: Nzhong_ning <zhong_ning@hoperun.com>
上级 4056bc9b
......@@ -18,20 +18,22 @@
#include <unistd.h>
#include "init_reboot.h"
#define REBOOT_CMD_NUMBER 2
int main(int argc, char* argv[])
{
if (argc > 2) {
if (argc > REBOOT_CMD_NUMBER) {
printf("usage: reboot shutdown\n reboot updater\n reboot updater[:options]\n reboot\n");
return 0;
}
if (argc == 2 && strcmp(argv[1], "shutdown") != 0 &&
if (argc == REBOOT_CMD_NUMBER && strcmp(argv[1], "shutdown") != 0 &&
strcmp(argv[1], "updater") != 0 &&
strncmp(argv[1], "updater:", strlen("updater:")) != 0 ) {
strncmp(argv[1], "updater:", strlen("updater:")) != 0) {
printf("usage: reboot shutdown\n reboot updater\n reboot updater[:options]\n reboot\n");
return 0;
}
int ret = 0;
if (argc == 2) {
if (argc == REBOOT_CMD_NUMBER) {
ret = DoReboot(argv[1]);
} else {
ret = DoReboot("NoArgument");
......
......@@ -15,8 +15,8 @@
#include <string.h>
#include <stdio.h>
#include "sys_param.h"
#include "securec.h"
#include "sys_param.h"
#define SERVICE_START_NUMBER 2
#define SERVICE_CONTROL_NUMBER 3
......@@ -71,13 +71,13 @@ int main(int argc, char** argv)
char serviceCtl[SERVICE_CONTROL_MAX_SIZE];
if (strcmp(argv[0], "start_service") == 0) {
if (strncpy_s(serviceCtl, sizeof(serviceCtl), "ohos.ctl.start", sizeof(serviceCtl) - 1) != EOK) {
printf("strncpy_s failed.\n");
return -1;
printf("strncpy_s failed.\n");
return -1;
}
} else if (strcmp(argv[0], "stop_service") == 0) {
if (strncpy_s(serviceCtl, sizeof(serviceCtl), "ohos.ctl.stop", sizeof(serviceCtl) - 1) != EOK) {
printf("strncpy_s failed.\n");
return -1;
printf("strncpy_s failed.\n");
return -1;
}
} else {
ServiceControl(argc, argv);
......
......@@ -145,7 +145,7 @@ int GetParamValue(char *symValue, char *paramValue, unsigned int paramLen)
// For ite ohos, do not support parameter operation. just do string copy
inline int GetParamValue(char *symValue, char *paramValue, unsigned int paramLen)
{
return strncpy_s(paramValue, paramLen, symValue, strlen(symValue)) == EOK ? 0 : -1;
return (strncpy_s(paramValue, paramLen, symValue, strlen(symValue)) == EOK) ? 0 : -1;
}
#endif
......@@ -164,7 +164,6 @@ struct CmdArgs* GetCmd(const char *cmdContent, const char *delim, int argsCount)
char tmpCmd[MAX_BUFFER];
size_t cmdLength = strlen(cmdContent);
if (cmdLength > MAX_BUFFER - 1) {
INIT_LOGE("command line is too larget, should not bigger than %d. ignore...\n", MAX_BUFFER);
FreeCmd(&ctx);
......@@ -201,7 +200,7 @@ struct CmdArgs* GetCmd(const char *cmdContent, const char *delim, int argsCount)
int index = ctx->argc;
while (token != NULL) {
// Too more arguments, treat rest of data as one argument
if (index == (argsCount -1)) {
if (index == (argsCount - 1)) {
break;
}
*token = '\0'; // replace it with '\0';
......@@ -834,7 +833,7 @@ static void DoSetrlimit(const char *cmdContent)
struct rlimit limit;
limit.rlim_cur = (rlim_t)atoi(ctx->argv[1]);
limit.rlim_max = (rlim_t )atoi(ctx->argv[rlimMaxPos]);
limit.rlim_max = (rlim_t)atoi(ctx->argv[rlimMaxPos]);
int rcs = -1;
for (unsigned int i = 0 ; i < sizeof(resource) / sizeof(char*); ++i) {
if (strcmp(ctx->argv[0], resource[i]) == 0) {
......
......@@ -693,7 +693,7 @@ void ParseAllServices(const cJSON* fileRoot)
tmp[i].socketCfg = NULL;
}
}
GetServiceOnRestart(curItem, &tmp[i]);
(void)GetServiceOnRestart(curItem, &tmp[i]);
}
// Increase service counter.
RegisterServices(retServices, servArrSize);
......
......@@ -50,7 +50,7 @@ static int CreateSocket(struct ServiceSocket *sockopt)
bzero(&addr,sizeof(addr));
addr.sun_family = AF_UNIX;
if (snprintf_s(addr.sun_path, sizeof(addr.sun_path), sizeof(addr.sun_path) - 1, HOS_SOCKET_DIR"/%s",
sockopt->name) < 0) {
sockopt->name) < 0) {
return -1;
}
if (access(addr.sun_path, F_OK)) {
......@@ -100,7 +100,7 @@ static int SetSocketEnv(int fd, char *name)
char pubName[MAX_SOCKET_ENV_PREFIX_LEN] = {0};
char val[MAX_SOCKET_FD_LEN] = {0};
if (snprintf_s(pubName, MAX_SOCKET_ENV_PREFIX_LEN, MAX_SOCKET_ENV_PREFIX_LEN - 1,
HOS_SOCKET_ENV_PREFIX"%s", name) < 0) {
HOS_SOCKET_ENV_PREFIX"%s", name) < 0) {
return -1;
}
if (snprintf_s(val, MAX_SOCKET_FD_LEN, MAX_SOCKET_FD_LEN - 1, "%d", fd) < 0) {
......
......@@ -522,7 +522,7 @@ static char* ReadFileToBuf()
break;
}
buffer = (char *)malloc((size_t)fileStat.st_size + 1);
buffer = static_cast<char*>malloc((size_t)fileStat.st_size + 1);
if (buffer == nullptr) {
break;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册