mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
nsh: Using sizeof() to get string length of char array
Changed from calling `strlen()` at runtime to using `sizeof()` at compile time. Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
parent
c052bd8377
commit
b3e1077f87
1 changed files with 29 additions and 31 deletions
|
|
@ -248,28 +248,32 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline);
|
|||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const char g_token_separator[] = " \t\n";
|
||||
static const char g_quote_separator[] = "'\"`";
|
||||
static const char g_token_separator[] = " \t\n";
|
||||
static const char g_quote_separator[] = "'\"`";
|
||||
#ifndef NSH_DISABLE_SEMICOLON
|
||||
static const char g_line_separator[] = "\"'#;\n";
|
||||
static const char g_line_separator[] = "\"'#;\n";
|
||||
#endif
|
||||
#ifdef CONFIG_NSH_ARGCAT
|
||||
static const char g_arg_separator[] = "`$";
|
||||
static const char g_arg_separator[] = "`$";
|
||||
#endif
|
||||
static const char g_redirect_out1[] = ">";
|
||||
static const char g_redirect_out2[] = ">>";
|
||||
static const char g_redirect_in1[] = "<";
|
||||
static const char g_redirect_out1[] = ">";
|
||||
static const size_t g_redirect_out1_len = sizeof(g_redirect_out1) - 1;
|
||||
static const char g_redirect_out2[] = ">>";
|
||||
static const size_t g_redirect_out2_len = sizeof(g_redirect_out2) - 1;
|
||||
static const char g_redirect_in1[] = "<";
|
||||
static const size_t g_redirect_in1_len = sizeof(g_redirect_in1) - 1;
|
||||
#ifdef CONFIG_NSH_PIPELINE
|
||||
static const char g_pipeline1[] = "|";
|
||||
static const char g_pipeline1[] = "|";
|
||||
static const size_t g_pipeline1_len = sizeof(g_pipeline1) - 1;
|
||||
#endif
|
||||
#ifdef NSH_HAVE_VARS
|
||||
static const char g_exitstatus[] = "?";
|
||||
static const char g_lastpid[] = "!";
|
||||
static const char g_success[] = "0";
|
||||
static const char g_failure[] = "1";
|
||||
static const char g_exitstatus[] = "?";
|
||||
static const char g_lastpid[] = "!";
|
||||
static const char g_success[] = "0";
|
||||
static const char g_failure[] = "1";
|
||||
#endif
|
||||
#ifdef NEED_NULLSTRING
|
||||
static const char g_nullstring[] = "";
|
||||
static const char g_nullstring[] = "";
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -2447,12 +2451,6 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
|
|||
#ifdef CONFIG_NSH_PIPELINE
|
||||
bool bg_save = false;
|
||||
#endif
|
||||
size_t redirect_out1_len = strlen(g_redirect_out1);
|
||||
size_t redirect_out2_len = strlen(g_redirect_out2);
|
||||
size_t redirect_in1_len = strlen(g_redirect_in1);
|
||||
#ifdef CONFIG_NSH_PIPELINE
|
||||
size_t pipeline1_len = strlen(g_pipeline1);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
|
||||
char tracebuf[CONFIG_NSH_LINELEN + 1];
|
||||
|
|
@ -2601,12 +2599,12 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
|
|||
}
|
||||
}
|
||||
|
||||
if (!strncmp(argv[argc], g_redirect_out2, redirect_out2_len))
|
||||
if (!strncmp(argv[argc], g_redirect_out2, g_redirect_out2_len))
|
||||
{
|
||||
FAR char *arg;
|
||||
if (argv[argc][redirect_out2_len])
|
||||
if (argv[argc][g_redirect_out2_len])
|
||||
{
|
||||
arg = &argv[argc][redirect_out2_len];
|
||||
arg = &argv[argc][g_redirect_out2_len];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -2625,12 +2623,12 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
|
|||
param.oflags_out = O_WRONLY | O_CREAT | O_APPEND;
|
||||
param.file_out = nsh_getfullpath(vtbl, arg);
|
||||
}
|
||||
else if (!strncmp(argv[argc], g_redirect_out1, redirect_out1_len))
|
||||
else if (!strncmp(argv[argc], g_redirect_out1, g_redirect_out1_len))
|
||||
{
|
||||
FAR char *arg;
|
||||
if (argv[argc][redirect_out1_len])
|
||||
if (argv[argc][g_redirect_out1_len])
|
||||
{
|
||||
arg = &argv[argc][redirect_out1_len];
|
||||
arg = &argv[argc][g_redirect_out1_len];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -2649,12 +2647,12 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
|
|||
param.oflags_out = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
param.file_out = nsh_getfullpath(vtbl, arg);
|
||||
}
|
||||
else if (!strncmp(argv[argc], g_redirect_in1, redirect_in1_len))
|
||||
else if (!strncmp(argv[argc], g_redirect_in1, g_redirect_in1_len))
|
||||
{
|
||||
FAR char *arg;
|
||||
if (argv[argc][redirect_in1_len])
|
||||
if (argv[argc][g_redirect_in1_len])
|
||||
{
|
||||
arg = &argv[argc][redirect_in1_len];
|
||||
arg = &argv[argc][g_redirect_in1_len];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -2674,14 +2672,14 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline)
|
|||
param.file_in = nsh_getfullpath(vtbl, arg);
|
||||
}
|
||||
#ifdef CONFIG_NSH_PIPELINE
|
||||
else if (!strncmp(argv[argc], g_pipeline1, pipeline1_len))
|
||||
else if (!strncmp(argv[argc], g_pipeline1, g_pipeline1_len))
|
||||
{
|
||||
FAR char *arg;
|
||||
FAR char *sh_argv[4];
|
||||
|
||||
if (argv[argc][pipeline1_len])
|
||||
if (argv[argc][g_pipeline1_len])
|
||||
{
|
||||
arg = &argv[argc][pipeline1_len];
|
||||
arg = &argv[argc][g_pipeline1_len];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue