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

Mike Frysinger vapier at gentoo.org
Mon Jan 23 07:30:28 CET 2012


Signed-off-by: Mike Frysinger <vapier at gentoo.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



More information about the U-Boot mailing list