[U-Boot] [PATCH 6/6] sandbox: add getenv support

Simon Glass sjg at chromium.org
Tue Jan 24 01:44:15 CET 2012


Hi Mike,

On Sun, Jan 22, 2012 at 10:30 PM, Mike Frysinger <vapier at gentoo.org> wrote:
> Signed-off-by: Mike Frysinger <vapier at gentoo.org>

Acked-by: Simon Glass <sjg at chromium.org>

> ---
>  arch/sandbox/cpu/os.c |   13 +++++++++++++
>  include/os.h          |    1 +
>  2 files changed, 14 insertions(+), 0 deletions(-)
>
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index 1d3e54f..4428f57 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -129,6 +129,19 @@ u64 os_get_nsec(void)
>  #endif
>  }
>
> +const char *os_getenv(const char *name)
> +{
> +       /* We can't use getenv() as u-boot provides it own */
> +       extern char **environ;
> +       size_t i, len = strlen(name);
> +
> +       for (i = 0; environ[i]; ++i)
> +               if (!strncmp(name, environ[i], len) && environ[i][len] == '=')
> +                       return &environ[i][len + 1];
> +
> +       return NULL;
> +}
> +
>  extern char **sb_argv;
>  const char *os_getopt(const char *name, int has_arg)
>  {
> diff --git a/include/os.h b/include/os.h
> index cb88509..095a2ce 100644
> --- a/include/os.h
> +++ b/include/os.h
> @@ -112,6 +112,7 @@ void os_usleep(unsigned long usec);
>  */
>  u64 os_get_nsec(void);
>
> +const char *os_getenv(const char *name);
>  const char *os_getopt(const char *name, int has_arg);
>
>  #endif
> --
> 1.7.8.3
>

Is this used by earlier patches (iwc it probably should go earlier) or
is it new?

I suppose we can use linker magic to make these sorts of functions
available to os.c, but your way seems nicer.

Regards,
Simon


More information about the U-Boot mailing list