env: add env_delete()
Change-Id: I3a94942b1670e641c8558c64dabca0155e53e2ea Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
This commit is contained in:
parent
736ece61eb
commit
3c9ee70130
31
cmd/nvedit.c
31
cmd/nvedit.c
|
|
@ -533,6 +533,37 @@ int env_exist(const char *varname, const char *varvalue)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int env_delete(const char *varname, const char *varvalue)
|
||||
{
|
||||
const char *str;
|
||||
char *value, *start;
|
||||
|
||||
/* before import into hashtable */
|
||||
if (!(gd->flags & GD_FLG_ENV_READY) || !varname)
|
||||
return 1;
|
||||
|
||||
value = env_get(varname);
|
||||
if (value) {
|
||||
start = strstr(value, varvalue);
|
||||
if (start) {
|
||||
/* varvalue is not the last property */
|
||||
str = strstr(start, " ");
|
||||
if (str) {
|
||||
/* Terminate, so cmdline can be dest for strcat() */
|
||||
*start = '\0';
|
||||
/* +1 to skip white space */
|
||||
strcat((char *)value, (str + 1));
|
||||
/* varvalue is the last property */
|
||||
} else {
|
||||
/* skip white space */
|
||||
*(start - 1) = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an environment variable to an integer value
|
||||
*
|
||||
|
|
|
|||
|
|
@ -349,6 +349,15 @@ int env_update(const char *varname, const char *varvalue);
|
|||
*/
|
||||
int env_exist(const char *varname, const char *varvalue);
|
||||
|
||||
/**
|
||||
* env_delete() - delete sub value of an environment variable
|
||||
*
|
||||
* @varname: Variable to look up
|
||||
* @value: Item head of value to delete
|
||||
* @return 0 if ok, 1 on error
|
||||
*/
|
||||
int env_delete(const char *varname, const char *varvalue);
|
||||
|
||||
/**
|
||||
* env_set_ulong() - set an environment variable to an integer
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue