refactor: initHookRegister moved to atInitRegister; strlcpy -> strncpy

portability.
This commit is contained in:
Jerzy Jamroz
2025-02-06 09:56:17 +01:00
committed by Andrew Johnson
parent f3e24ea8e3
commit 16fd65639a

View File

@@ -54,9 +54,9 @@ static struct cmditem* newItem(char* cmd)
{
struct cmditem* item = mallocMustSucceed(sizeof(struct cmditem) + strlen(cmd) + 1,
ERL_ERROR " atInit: "
"failed to allocate memory for cmditem");
"failed to allocate memory for cmditem\n");
item->cmd = (char*)(item + 1);
strlcpy(item->cmd, cmd, strlen(cmd) + 1);
strncpy(item->cmd, cmd, strlen(cmd) + 1);
ellAdd(&s_cmdlist, &item->node);
@@ -71,7 +71,6 @@ static const iocshFuncDef atInitDef = {
static void atInitFunc(const iocshArgBuf* args)
{
static int first_time = 1;
char* cmd = args[0].sval;
if (s_initendflag) {
@@ -86,11 +85,6 @@ static void atInitFunc(const iocshArgBuf* args)
return;
}
if (first_time) {
first_time = 0;
initHookRegister(atInitHook);
}
newItem(cmd);
}
@@ -100,5 +94,6 @@ void atInitRegister(void)
if (first_time) {
first_time = 0;
iocshRegister(&atInitDef, atInitFunc);
initHookRegister(atInitHook);
}
}