X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fcmd_nvedit.c;h=5bcc324675eb7535c9e103cd473134122b83e376;hb=8ad59c9a7bef49a18078888ad8eba8e87737c3b2;hp=f8dc38e89a2d3e0e54c1abf28cdee09cc32e0e24;hpb=be29df6a1ac286e6c482828db28ca96e187c7e00;p=u-boot diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index f8dc38e89a..5bcc324675 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -7,23 +7,7 @@ * * Copyright 2011 Freescale Semiconductor, Inc. * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -173,10 +157,8 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag, grep_how = H_MATCH_SUBSTR; /* default: substring search */ grep_what = H_MATCH_BOTH; /* default: grep names and values */ - while (argc > 1 && **(argv + 1) == '-') { - char *arg = *++argv; - - --argc; + while (--argc > 0 && **++argv == '-') { + char *arg = *argv; while (*++arg) { switch (*arg) { #ifdef CONFIG_REGEX @@ -314,7 +296,7 @@ int setenv(const char *varname, const char *varvalue) /** * Set an environment variable to an integer value * - * @param varname Environmet variable to set + * @param varname Environment variable to set * @param value Value to set it to * @return 0 if ok, 1 on error */ @@ -329,7 +311,7 @@ int setenv_ulong(const char *varname, ulong value) /** * Set an environment variable to an value in hex * - * @param varname Environmet variable to set + * @param varname Environment variable to set * @param value Value to set it to * @return 0 if ok, 1 on error */ @@ -1075,6 +1057,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 */ @@ -1110,6 +1109,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) @@ -1152,6 +1154,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