getenv.c 509 B

123456789101112131415161718192021222324252627
  1. /* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
  2. * This file is part of the Linux-8086 C library and is distributed
  3. * under the GNU Library General Public License.
  4. */
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <malloc.h>
  8. extern char **environ;
  9. char *getenv(var)
  10. const char *var;
  11. {
  12. char **p;
  13. int len;
  14. len = strlen(var);
  15. if (!environ)
  16. return 0;
  17. for (p = environ; *p; p++) {
  18. if (memcmp(var, *p, len) == 0 && (*p)[len] == '=')
  19. return *p + len + 1;
  20. }
  21. return 0;
  22. }