getenv.c 756 B

123456789101112131415161718192021222324252627282930313233
  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. libc_hidden_proto(getenv)
  10. /* Experimentally off - libc_hidden_proto(memcmp) */
  11. /* Experimentally off - libc_hidden_proto(strlen) */
  12. /* IEEE Std 1003.1-2001 says getenv need not be thread safe, so
  13. * don't bother locking access to __environ */
  14. char *getenv(const char *var)
  15. {
  16. int len;
  17. char **ep;
  18. if (!(ep=__environ))
  19. return NULL;
  20. len = strlen(var);
  21. while(*ep) {
  22. if (memcmp(var, *ep, len) == 0 && (*ep)[len] == '=') {
  23. return *ep + len + 1;
  24. }
  25. ep++;
  26. }
  27. return NULL;
  28. }
  29. libc_hidden_def(getenv)