summaryrefslogtreecommitdiff
path: root/src/env/getenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/env/getenv.c')
-rw-r--r--src/env/getenv.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/env/getenv.c b/src/env/getenv.c
index 00c1bce0..cf34672c 100644
--- a/src/env/getenv.c
+++ b/src/env/getenv.c
@@ -2,13 +2,14 @@
#include <string.h>
#include "libc.h"
+char *__strchrnul(const char *, int);
+
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;
+ size_t l = __strchrnul(name, '=') - name;
+ if (l && !name[l] && __environ)
+ for (char **e = __environ; *e; e++)
+ if (!strncmp(name, *e, l) && l[*e] == '=')
+ return *e + l+1;
+ return 0;
}