env: Use getenv_yesno() more generally

Move the getenv_yesno() to env_common.c and change most checks for
'y' or 'n' to use this helper.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
This commit is contained in:
Joe Hershberger
2012-12-11 22:16:22 -06:00
committed by Tom Rini
parent 7afcf3a55b
commit ec8a252cd4
16 changed files with 56 additions and 79 deletions

View File

@@ -81,6 +81,20 @@ const uchar *env_get_addr(int index)
return &default_environment[index];
}
/*
* Read an environment variable as a boolean
* Return -1 if variable does not exist (default to true)
*/
int getenv_yesno(const char *var)
{
char *s = getenv(var);
if (s == NULL)
return -1;
return (*s == '1' || *s == 'y' || *s == 'Y' || *s == 't' || *s == 'T') ?
1 : 0;
}
void set_default_env(const char *s)
{
int flags = 0;