summaryrefslogtreecommitdiffstats
path: root/usr/klibc/getenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/getenv.c')
-rw-r--r--usr/klibc/getenv.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/usr/klibc/getenv.c b/usr/klibc/getenv.c
new file mode 100644
index 0000000..3a4ae5e
--- /dev/null
+++ b/usr/klibc/getenv.c
@@ -0,0 +1,24 @@
+/*
+ * getenv.c
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+char *getenv(const char *name)
+{
+ char **p, *q;
+ int len = strlen(name);
+
+ if (!environ)
+ return NULL;
+
+ for (p = environ; (q = *p); p++) {
+ if (!strncmp(name, q, len) && q[len] == '=') {
+ return q + (len + 1);
+ }
+ }
+
+ return NULL;
+}