drop direct use of stat syscalls in fchmodat
[musl] / src / env / getenv.c
index 00c1bce..a90d39c 100644 (file)
@@ -1,14 +1,13 @@
 #include <stdlib.h>
 #include <string.h>
-#include "libc.h"
+#include <unistd.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;
+       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;
 }