From ec8a252cd492a7a409d6912aebeff34bb9e1e1e1 Mon Sep 17 00:00:00 2001 From: Joe Hershberger Date: Tue, 11 Dec 2012 22:16:22 -0600 Subject: 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 --- common/env_common.c | 14 ++++++++++++++ common/image.c | 6 ------ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'common') diff --git a/common/env_common.c b/common/env_common.c index a960aa8033..067fe3f4c1 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -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; diff --git a/common/image.c b/common/image.c index e93b6e89cf..69e888c5d5 100644 --- a/common/image.c +++ b/common/image.c @@ -416,12 +416,6 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, /* Shared dual-format routines */ /*****************************************************************************/ #ifndef USE_HOSTCC -int getenv_yesno(char *var) -{ - char *s = getenv(var); - return (s && (*s == 'n')) ? 0 : 1; -} - ulong getenv_bootm_low(void) { char *s = getenv("bootm_low"); -- cgit v1.2.3