Skip to content

Commit

Permalink
refactor: const adjustment.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerzyjamroz committed Feb 14, 2025
1 parent 7f00073 commit 80a7034
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions modules/libcom/src/iocsh/atInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ struct cmditem {
char *cmd;
};

static ELLLIST s_cmdlist = ELLLIST_INIT;
static int s_initendflag = 0; // Defines the end of the initialization
static ELLLIST cmdList = ELLLIST_INIT;
static int initEndFlag = 0; // Defines the end of the initialization

static void atInitHook(initHookState state)
static void atInitHook(const initHookState state)
{
struct cmditem *item = NULL;

if (state != initHookAfterIocRunning)
return;

while ((item = (struct cmditem *)ellGet(&s_cmdlist))) {
while ((item = (struct cmditem *)ellGet(&cmdList))) {
printf("%s\n", item->cmd);

if (iocshCmd(item->cmd))
Expand All @@ -48,18 +48,17 @@ static void atInitHook(initHookState state)
free(item);
}

s_initendflag = 1;
initEndFlag = 1;
}

static struct cmditem *newItem(const char *cmd)
{
const size_t cmd_len = strnlen(cmd, MAX_STRING_SIZE - 1) + 1;

struct cmditem *item = mallocMustSucceed(sizeof(struct cmditem) + cmd_len, "atInit");
const size_t cmd_len = strnlen(cmd, 32768 - 1) + 1;
struct cmditem *const item = mallocMustSucceed(sizeof(struct cmditem) + cmd_len, "atInit");
item->cmd = (char *)(item + 1);
memcpy(item->cmd, cmd, cmd_len);

ellAdd(&s_cmdlist, &item->node);
ellAdd(&cmdList, &item->node);

return item;
}
Expand All @@ -74,9 +73,9 @@ static const iocshFuncDef atInitDef = {

static void atInitFunc(const iocshArgBuf *args)
{
char *cmd = args[0].sval;
const char *cmd = args[0].sval;

if (s_initendflag) {
if (initEndFlag) {
printf(ERL_WARNING " atInit: "
"can only be used before iocInit (check help)\n");
return;
Expand Down

0 comments on commit 80a7034

Please sign in to comment.