getenv.c 534 B

123456789101112131415161718192021222324252627
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. char *
  9. getenv(const char *name)
  10. {
  11. register char **v = environ;
  12. register const char *p, *q;
  13. if (v == NULL || name == NULL)
  14. return (char *)NULL;
  15. while ((p = *v++) != NULL) {
  16. q = name;
  17. while (*q && (*q == *p++))
  18. q++;
  19. if (*q || (*p != '='))
  20. continue;
  21. return (char *)p + 1;
  22. }
  23. return (char *)NULL;
  24. }