getenv.c 625 B

123456789101112131415161718192021222324252627282930
  1. /* getenv.c for uClibc
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <string.h>
  7. #include <unistd.h>
  8. #include <stdlib.h>
  9. /* IEEE Std 1003.1-2001 says getenv need not be thread safe, so
  10. * don't bother locking access to __environ */
  11. char *getenv(const char *var)
  12. {
  13. int len;
  14. char **ep;
  15. if (!(ep=__environ))
  16. return NULL;
  17. len = strlen(var);
  18. while(*ep) {
  19. if (memcmp(var, *ep, len) == 0 && (*ep)[len] == '=') {
  20. return *ep + len + 1;
  21. }
  22. ep++;
  23. }
  24. return NULL;
  25. }
  26. libc_hidden_weak(getenv)