getenv.c 306 B

1234567891011121314
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include "libc.h"
  5. char *getenv(const char *name)
  6. {
  7. size_t l = __strchrnul(name, '=') - name;
  8. if (l && !name[l] && __environ)
  9. for (char **e = __environ; *e; e++)
  10. if (!strncmp(name, *e, l) && l[*e] == '=')
  11. return *e + l+1;
  12. return 0;
  13. }