aboutsummaryrefslogtreecommitdiff
path: root/src/env/getenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/env/getenv.c')
-rw-r--r--src/env/getenv.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/env/getenv.c b/src/env/getenv.c
new file mode 100644
index 0000000..00c1bce
--- /dev/null
+++ b/src/env/getenv.c
@@ -0,0 +1,14 @@
+#include <stdlib.h>
+#include <string.h>
+#include "libc.h"
+
+char *getenv(const char *name)
+{
+ int i;
+ size_t l = strlen(name);
+ if (!__environ || !*name || strchr(name, '=')) return NULL;
+ for (i=0; __environ[i] && (strncmp(name, __environ[i], l)
+ || __environ[i][l] != '='); i++);
+ if (__environ[i]) return __environ[i] + l+1;
+ return NULL;
+}