summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAndrew Ruder <andrew.ruder@elecsyscorp.com>2013-10-22 19:07:34 -0500
committerTom Rini <trini@ti.com>2013-11-08 09:38:24 -0500
commit88733e2c65b1b118e6e1a942d62a48ce62a5ea40 (patch)
treed34db65ce88b141c2b737a0767084a0899f17719 /common
parent8948794a273a6b4925d1acc5788ce804f0ceb410 (diff)
cmd_nvedit.c: Add env exists command
env exists is a way to test (in hush) if an environment variable exists. A workaround existed using printenv but this new command doesn't require all the stdout/stderr redirection to prevent printing information to the screen. Example: $ set testexists 1 $ env exists testexists && echo "yes" yes $ env exists testexists || echo "no" $ set testexists $ env exists testexists && echo "yes" $ env exists testexists || echo "no" no $ Signed-off-by: Andrew Ruder <andrew.ruder@elecsyscorp.com>
Diffstat (limited to 'common')
-rw-r--r--common/cmd_nvedit.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index ba9ba16972c..0d4d02cfe0a 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -1059,6 +1059,23 @@ sep_err:
}
#endif
+#if defined(CONFIG_CMD_ENV_EXISTS)
+static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ ENTRY e, *ep;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ e.key = argv[1];
+ e.data = NULL;
+ hsearch_r(e, FIND, &ep, &env_htab, 0);
+
+ return (ep == NULL) ? 1 : 0;
+}
+#endif
+
/*
* New command line interface: "env" command with subcommands
*/
@@ -1094,6 +1111,9 @@ static cmd_tbl_t cmd_env_sub[] = {
U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
#endif
U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
+#if defined(CONFIG_CMD_ENV_EXISTS)
+ U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""),
+#endif
};
#if defined(CONFIG_NEEDS_MANUAL_RELOC)
@@ -1136,6 +1156,9 @@ static char env_help_text[] =
#if defined(CONFIG_CMD_EDITENV)
"env edit name - edit environment variable\n"
#endif
+#if defined(CONFIG_CMD_ENV_EXISTS)
+ "env exists name - tests for existence of variable\n"
+#endif
#if defined(CONFIG_CMD_EXPORTENV)
"env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
#endif