summaryrefslogtreecommitdiff
path: root/src/stdlib/getenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib/getenv.c')
-rw-r--r--src/stdlib/getenv.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/stdlib/getenv.c b/src/stdlib/getenv.c
new file mode 100644
index 00000000..edf5c4f9
--- /dev/null
+++ b/src/stdlib/getenv.c
@@ -0,0 +1,31 @@
+#include <stdlib.h>
+#include "string.h"
+
+/** get an environment variable **/
+
+char * getenv(const char * name)
+{
+ extern char **environ;
+ int i = 0;
+
+ while (environ[i] != 0) {
+ if (!strncmp(environ[i], name, strlen(name)) && environ[i][strlen(name)] == '=')
+ return environ[i];
+ i++;
+ }
+
+ return NULL;
+}
+
+/***
+read the environment variable ARGUMENT(name) from the host environment.
+***/
+
+/*
+UNDEFINED(Modifying the returned string)
+IMPLEMENTATION(The set of environment variable names)
+IMPLEMENTATION(The method of altering the environment)
+RETURN_FAILURE(CONSTANT(NULL))
+RETURN_SUCCESS(a pointer to the environment string)
+STDC(1)
+*/